Skip to content

Commit

Permalink
Don't trigger while_let_on_iterator when the iterator is recreated ev…
Browse files Browse the repository at this point in the history
…ery iteration
  • Loading branch information
flip1995 committed Apr 25, 2020
1 parent 6ffe725 commit eadd9d2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
) = (pat, &match_expr.kind)
{
let iter_expr = &method_args[0];

// Don't lint when the iterator is recreated on every iteration
if_chain! {
if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind;
if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR);
if implements_trait(cx, cx.tables.expr_ty(iter_expr), iter_def_id, &[]);
then {
return;
}
}

let lhs_constructor = last_path_segment(qpath);
if method_path.ident.name == sym!(next)
&& match_trait_method(cx, match_expr, &paths::ITERATOR)
Expand Down

0 comments on commit eadd9d2

Please sign in to comment.