Skip to content

Commit eadd9d2

Browse files
committed
Don't trigger while_let_on_iterator when the iterator is recreated every iteration
1 parent 6ffe725 commit eadd9d2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clippy_lints/src/loops.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
566566
) = (pat, &match_expr.kind)
567567
{
568568
let iter_expr = &method_args[0];
569+
570+
// Don't lint when the iterator is recreated on every iteration
571+
if_chain! {
572+
if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind;
573+
if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR);
574+
if implements_trait(cx, cx.tables.expr_ty(iter_expr), iter_def_id, &[]);
575+
then {
576+
return;
577+
}
578+
}
579+
569580
let lhs_constructor = last_path_segment(qpath);
570581
if method_path.ident.name == sym!(next)
571582
&& match_trait_method(cx, match_expr, &paths::ITERATOR)

0 commit comments

Comments
 (0)