Skip to content

Commit 2df56ca

Browse files
committed
Auto merge of rust-lang#14755 - poliorcetics:clippy-fixes, r=Veykril
Fix: a TODO and some clippy fixes - fix(todo): implement IntoIterator for ArenaMap<IDX, V> - chore: remove unused method - fix: remove useless `return`s - fix: various clippy lints - fix: simplify boolean test to a single negation
2 parents 1d1a119 + 5411836 commit 2df56ca

File tree

10 files changed

+71
-30
lines changed

10 files changed

+71
-30
lines changed

crates/flycheck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl CargoActor {
485485

486486
error.push_str(line);
487487
error.push('\n');
488-
return false;
488+
false
489489
};
490490
let output = streaming_output(
491491
self.stdout,

crates/hir-def/src/body/pretty.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
3535
DefWithBodyId::VariantId(it) => {
3636
let src = it.parent.child_source(db);
3737
let variant = &src.value[it.local_id];
38-
let name = match &variant.name() {
38+
match &variant.name() {
3939
Some(name) => name.to_string(),
4040
None => "_".to_string(),
41-
};
42-
format!("{name}")
41+
}
4342
}
4443
};
4544

@@ -456,7 +455,7 @@ impl<'a> Printer<'a> {
456455
fn print_block(
457456
&mut self,
458457
label: Option<&str>,
459-
statements: &Box<[Statement]>,
458+
statements: &[Statement],
460459
tail: &Option<la_arena::Idx<Expr>>,
461460
) {
462461
self.whitespace();
@@ -466,7 +465,7 @@ impl<'a> Printer<'a> {
466465
w!(self, "{{");
467466
if !statements.is_empty() || tail.is_some() {
468467
self.indented(|p| {
469-
for stmt in &**statements {
468+
for stmt in statements {
470469
p.print_stmt(stmt);
471470
}
472471
if let Some(tail) = tail {

crates/parser/src/grammar/expressions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ fn postfix_expr(
417417
allow_calls = true;
418418
block_like = BlockLike::NotBlock;
419419
}
420-
return (lhs, block_like);
420+
(lhs, block_like)
421421
}
422422

423423
fn postfix_dot_expr<const FLOAT_RECOVERY: bool>(

crates/parser/src/grammar/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::*;
1919
// struct S;
2020
pub(super) fn mod_contents(p: &mut Parser<'_>, stop_on_r_curly: bool) {
2121
attributes::inner_attrs(p);
22-
while !p.at(EOF) && !(p.at(T!['}']) && stop_on_r_curly) {
22+
while !(p.at(EOF) || (p.at(T!['}']) && stop_on_r_curly)) {
2323
item_or_macro(p, stop_on_r_curly);
2424
}
2525
}

crates/parser/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'t> Parser<'t> {
205205
marker.bomb.defuse();
206206
marker = new_marker;
207207
};
208-
self.pos += 1 as usize;
208+
self.pos += 1;
209209
self.push_event(Event::FloatSplitHack { ends_in_dot });
210210
(ends_in_dot, marker)
211211
}

crates/parser/src/shortcuts.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ impl<'a> LexedStr<'a> {
4646
// Tag the token as joint if it is float with a fractional part
4747
// we use this jointness to inform the parser about what token split
4848
// event to emit when we encounter a float literal in a field access
49-
if kind == SyntaxKind::FLOAT_NUMBER {
50-
if !self.text(i).ends_with('.') {
51-
res.was_joint();
52-
}
49+
if kind == SyntaxKind::FLOAT_NUMBER && !self.text(i).ends_with('.') {
50+
res.was_joint();
5351
}
5452
}
5553

crates/syntax/src/ast/expr_ext.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ impl ast::BlockExpr {
370370
match parent.kind() {
371371
FOR_EXPR | IF_EXPR => parent
372372
.children()
373-
.filter(|it| ast::Expr::can_cast(it.kind()))
374-
.next()
373+
.find(|it| ast::Expr::can_cast(it.kind()))
375374
.map_or(true, |it| it == *self.syntax()),
376375
LET_ELSE | FN | WHILE_EXPR | LOOP_EXPR | CONST_BLOCK_PAT => false,
377376
_ => true,

crates/syntax/src/ast/make.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn ty_alias(
195195
}
196196
}
197197

198-
s.push_str(";");
198+
s.push(';');
199199
ast_from_text(&s)
200200
}
201201

@@ -399,7 +399,7 @@ pub fn hacky_block_expr(
399399
format_to!(buf, " {t}\n")
400400
} else if kind == SyntaxKind::WHITESPACE {
401401
let content = t.text().trim_matches(|c| c != '\n');
402-
if content.len() >= 1 {
402+
if !content.is_empty() {
403403
format_to!(buf, "{}", &content[1..])
404404
}
405405
}

crates/vfs/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ pub enum ChangeKind {
109109
}
110110

111111
impl Vfs {
112-
/// Amount of files currently stored.
113-
///
114-
/// Note that this includes deleted files.
115-
pub fn len(&self) -> usize {
116-
self.data.len()
117-
}
118-
119112
/// Id of the given path if it exists in the `Vfs` and is not deleted.
120113
pub fn file_id(&self, path: &VfsPath) -> Option<FileId> {
121114
self.interner.get(path).filter(|&it| self.get(it).is_some())

lib/la-arena/src/map.rs

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::iter::Enumerate;
12
use std::marker::PhantomData;
23

34
use crate::Idx;
@@ -94,12 +95,6 @@ impl<T, V> ArenaMap<Idx<T>, V> {
9495
.filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_mut()?)))
9596
}
9697

97-
/// Returns an iterator over the arena indexes and values in the map.
98-
// FIXME: Implement `IntoIterator` trait.
99-
pub fn into_iter(self) -> impl Iterator<Item = (Idx<T>, V)> + DoubleEndedIterator {
100-
self.v.into_iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o?)))
101-
}
102-
10398
/// Gets the given key's corresponding entry in the map for in-place manipulation.
10499
pub fn entry(&mut self, idx: Idx<T>) -> Entry<'_, Idx<T>, V> {
105100
let idx = Self::to_idx(idx);
@@ -154,6 +149,63 @@ impl<T, V> FromIterator<(Idx<V>, T)> for ArenaMap<Idx<V>, T> {
154149
}
155150
}
156151

152+
pub struct ArenaMapIter<IDX, V> {
153+
iter: Enumerate<std::vec::IntoIter<Option<V>>>,
154+
_ty: PhantomData<IDX>,
155+
}
156+
157+
impl<T, V> IntoIterator for ArenaMap<Idx<T>, V> {
158+
type Item = (Idx<T>, V);
159+
160+
type IntoIter = ArenaMapIter<Idx<T>, V>;
161+
162+
fn into_iter(self) -> Self::IntoIter {
163+
let iter = self.v.into_iter().enumerate();
164+
Self::IntoIter { iter, _ty: PhantomData }
165+
}
166+
}
167+
168+
impl<T, V> ArenaMapIter<Idx<T>, V> {
169+
fn mapper((idx, o): (usize, Option<V>)) -> Option<(Idx<T>, V)> {
170+
Some((ArenaMap::<Idx<T>, V>::from_idx(idx), o?))
171+
}
172+
}
173+
174+
impl<T, V> Iterator for ArenaMapIter<Idx<T>, V> {
175+
type Item = (Idx<T>, V);
176+
177+
#[inline]
178+
fn next(&mut self) -> Option<Self::Item> {
179+
for next in self.iter.by_ref() {
180+
match Self::mapper(next) {
181+
Some(r) => return Some(r),
182+
None => continue,
183+
}
184+
}
185+
186+
None
187+
}
188+
189+
#[inline]
190+
fn size_hint(&self) -> (usize, Option<usize>) {
191+
self.iter.size_hint()
192+
}
193+
}
194+
195+
impl<T, V> DoubleEndedIterator for ArenaMapIter<Idx<T>, V> {
196+
#[inline]
197+
fn next_back(&mut self) -> Option<Self::Item> {
198+
while let Some(next_back) = self.iter.next_back() {
199+
match Self::mapper(next_back) {
200+
Some(r) => return Some(r),
201+
None => continue,
202+
}
203+
}
204+
205+
None
206+
}
207+
}
208+
157209
/// A view into a single entry in a map, which may either be vacant or occupied.
158210
///
159211
/// This `enum` is constructed from the [`entry`] method on [`ArenaMap`].

0 commit comments

Comments
 (0)