Skip to content

Commit fe25dbe

Browse files
committed
Fix while_let_on_iterator suggestion and make it MachineApplicable
1 parent f9c1acb commit fe25dbe

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

clippy_lints/src/loops.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -576,20 +576,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
576576
&& !is_iterator_used_after_while_let(cx, iter_expr)
577577
&& !is_nested(cx, expr, &method_args[0]))
578578
{
579-
let iterator = snippet(cx, method_args[0].span, "_");
579+
let mut applicability = Applicability::MachineApplicable;
580+
let iterator = snippet_with_applicability(cx, method_args[0].span, "_", &mut applicability);
580581
let loop_var = if pat_args.is_empty() {
581582
"_".to_string()
582583
} else {
583-
snippet(cx, pat_args[0].span, "_").into_owned()
584+
snippet_with_applicability(cx, pat_args[0].span, "_", &mut applicability).into_owned()
584585
};
585586
span_lint_and_sugg(
586587
cx,
587588
WHILE_LET_ON_ITERATOR,
588-
expr.span,
589+
expr.span.with_hi(match_expr.span.hi()),
589590
"this loop could be written as a `for` loop",
590591
"try",
591-
format!("for {} in {} {{ .. }}", loop_var, iterator),
592-
Applicability::HasPlaceholders,
592+
format!("for {} in {}", loop_var, iterator),
593+
applicability,
593594
);
594595
}
595596
}

0 commit comments

Comments
 (0)