Skip to content

Commit 34815a9

Browse files
committed
for_loop_over_fallibles: fix suggestion for "remove .next()" case
if the iterator is used after the loop, we need to use `.by_ref()`
1 parent 5128140 commit 34815a9

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

compiler/rustc_lint/src/for_loop_over_fallibles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopOverFallibles {
8282
warn.span_suggestion(
8383
recv.span.between(arg.span.shrink_to_hi()),
8484
format!("to iterate over `{recv_snip}` remove the call to `next`"),
85-
"",
85+
".by_ref()",
8686
Applicability::MaybeIncorrect
8787
);
8888
} else {

src/test/ui/lint/for_loop_over_fallibles.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ LL | for _ in [0; 0].iter().next() {}
3737
|
3838
help: to iterate over `[0; 0].iter()` remove the call to `next`
3939
|
40-
LL - for _ in [0; 0].iter().next() {}
41-
LL + for _ in [0; 0].iter() {}
42-
|
40+
LL | for _ in [0; 0].iter().by_ref() {}
41+
| ~~~~~~~~~
4342
help: consider using `if let` to clear intent
4443
|
4544
LL | if let Some(_) = [0; 0].iter().next() {}

0 commit comments

Comments
 (0)