diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-07-25 00:58:04 +0400 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-10-09 13:05:53 +0000 |
| commit | 23a7674e3eb7e860ae59e81acc0699926dd0797c (patch) | |
| tree | 063d694e049a2acaaf12e6f597357b8542c5d4f9 | |
| parent | 730856442387c9804581eae5927a5667171022ca (diff) | |
| download | rust-23a7674e3eb7e860ae59e81acc0699926dd0797c.tar.gz rust-23a7674e3eb7e860ae59e81acc0699926dd0797c.zip | |
`for_loop_over_fallibles`: fix suggestion for "remove `.next()`" case
if the iterator is used after the loop, we need to use `.by_ref()`
| -rw-r--r-- | compiler/rustc_lint/src/for_loop_over_fallibles.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/for_loop_over_fallibles.stderr | 5 |
2 files changed, 3 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/for_loop_over_fallibles.rs b/compiler/rustc_lint/src/for_loop_over_fallibles.rs index 69d8fd84b64..c8d5586d39f 100644 --- a/compiler/rustc_lint/src/for_loop_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loop_over_fallibles.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopOverFallibles { warn.span_suggestion( recv.span.between(arg.span.shrink_to_hi()), format!("to iterate over `{recv_snip}` remove the call to `next`"), - "", + ".by_ref()", Applicability::MaybeIncorrect ); } else { diff --git a/src/test/ui/lint/for_loop_over_fallibles.stderr b/src/test/ui/lint/for_loop_over_fallibles.stderr index 52eac945d85..56e3126dc09 100644 --- a/src/test/ui/lint/for_loop_over_fallibles.stderr +++ b/src/test/ui/lint/for_loop_over_fallibles.stderr @@ -37,9 +37,8 @@ LL | for _ in [0; 0].iter().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() {} - | +LL | for _ in [0; 0].iter().by_ref() {} + | ~~~~~~~~~ help: consider using `if let` to clear intent | LL | if let Some(_) = [0; 0].iter().next() {} |
