for_loop_over_fallibles: fix suggestion for "remove .next()" case
if the iterator is used after the loop, we need to use `.by_ref()`
This commit is contained in:
@@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopOverFallibles {
|
|||||||
warn.span_suggestion(
|
warn.span_suggestion(
|
||||||
recv.span.between(arg.span.shrink_to_hi()),
|
recv.span.between(arg.span.shrink_to_hi()),
|
||||||
format!("to iterate over `{recv_snip}` remove the call to `next`"),
|
format!("to iterate over `{recv_snip}` remove the call to `next`"),
|
||||||
"",
|
".by_ref()",
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -37,9 +37,8 @@ LL | for _ in [0; 0].iter().next() {}
|
|||||||
|
|
|
|
||||||
help: to iterate over `[0; 0].iter()` remove the call to `next`
|
help: to iterate over `[0; 0].iter()` remove the call to `next`
|
||||||
|
|
|
|
||||||
LL - for _ in [0; 0].iter().next() {}
|
LL | for _ in [0; 0].iter().by_ref() {}
|
||||||
LL + for _ in [0; 0].iter() {}
|
| ~~~~~~~~~
|
||||||
|
|
|
||||||
help: consider using `if let` to clear intent
|
help: consider using `if let` to clear intent
|
||||||
|
|
|
|
||||||
LL | if let Some(_) = [0; 0].iter().next() {}
|
LL | if let Some(_) = [0; 0].iter().next() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user