- if let ExprAddrOf(MutMutable, ref e) = expr.node {
- if let ExprAddrOf(MutMutable, _) = e.node {
- span_lint(cx, MUT_MUT, expr.span, "generally you want to avoid `&mut &mut _` if possible");
- } else {
- if let TyRef(_, TypeAndMut { mutbl: MutMutable, .. }) = cx.tcx.expr_ty(e).sty {
- span_lint(cx,
- MUT_MUT,
- expr.span,
- "this expression mutably borrows a mutable reference. Consider reborrowing");
- }
+ if let Some((_, arg, body)) = recover_for_loop(expr) {
+ // A `for` loop lowers to:
+ // ```rust
+ // match ::std::iter::Iterator::next(&mut iter) {
+ // // ^^^^
+ // ```
+ // Let's ignore the generated code.
+ intravisit::walk_expr(self, arg);
+ intravisit::walk_expr(self, body);
+ } else if let hir::ExprAddrOf(hir::MutMutable, ref e) = expr.node {
+ if let hir::ExprAddrOf(hir::MutMutable, _) = e.node {
+ span_lint(self.cx, MUT_MUT, expr.span, "generally you want to avoid `&mut &mut _` if possible");
+ } else if let TyRef(_, TypeAndMut { mutbl: hir::MutMutable, .. }) = self.cx.tcx.expr_ty(e).sty {
+ span_lint(self.cx,
+ MUT_MUT,
+ expr.span,
+ "this expression mutably borrows a mutable reference. Consider reborrowing");