diff options
| author | flip1995 <hello@philkrones.com> | 2020-04-25 20:00:00 +0200 |
|---|---|---|
| committer | flip1995 <hello@philkrones.com> | 2020-04-25 20:00:00 +0200 |
| commit | fe25dbe549aecd409897b00fe13c32072d498336 (patch) | |
| tree | 7d26f6c28f352acd3856687b5db0dceda31bd7c3 | |
| parent | f9c1acbc452e75123b0a481aa955d508972aa5f1 (diff) | |
| download | rust-fe25dbe549aecd409897b00fe13c32072d498336.tar.gz rust-fe25dbe549aecd409897b00fe13c32072d498336.zip | |
Fix while_let_on_iterator suggestion and make it MachineApplicable
| -rw-r--r-- | clippy_lints/src/loops.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index d76df908f09..56dd2795c60 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -576,20 +576,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { && !is_iterator_used_after_while_let(cx, iter_expr) && !is_nested(cx, expr, &method_args[0])) { - let iterator = snippet(cx, method_args[0].span, "_"); + let mut applicability = Applicability::MachineApplicable; + let iterator = snippet_with_applicability(cx, method_args[0].span, "_", &mut applicability); let loop_var = if pat_args.is_empty() { "_".to_string() } else { - snippet(cx, pat_args[0].span, "_").into_owned() + snippet_with_applicability(cx, pat_args[0].span, "_", &mut applicability).into_owned() }; span_lint_and_sugg( cx, WHILE_LET_ON_ITERATOR, - expr.span, + expr.span.with_hi(match_expr.span.hi()), "this loop could be written as a `for` loop", "try", - format!("for {} in {} {{ .. }}", loop_var, iterator), - Applicability::HasPlaceholders, + format!("for {} in {}", loop_var, iterator), + applicability, ); } } |
