@@ -7,7 +7,7 @@ use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}
77use rustc_hir:: { BinOpKind , BorrowKind , Expr , ExprKind , HirId , HirIdMap , Local , Mutability , Pat , PatKind , Stmt } ;
88use rustc_lint:: LateContext ;
99use rustc_middle:: hir:: nested_filter;
10- use rustc_middle:: ty:: Ty ;
10+ use rustc_middle:: ty:: { self , Ty } ;
1111use rustc_span:: source_map:: Spanned ;
1212use rustc_span:: symbol:: { sym, Symbol } ;
1313use rustc_typeck:: hir_ty_to_ty;
@@ -332,17 +332,20 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
332332 } else {
333333 // (&x).into_iter() ==> x.iter()
334334 // (&mut x).into_iter() ==> x.iter_mut()
335- match & arg. kind {
336- ExprKind :: AddrOf ( BorrowKind :: Ref , mutability, arg_inner)
337- if has_iter_method ( cx, cx. typeck_results ( ) . expr_ty ( arg_inner) ) . is_some ( ) =>
338- {
339- let meth_name = match mutability {
335+ let arg_ty = cx. typeck_results ( ) . expr_ty_adjusted ( arg) ;
336+ match & arg_ty. kind ( ) {
337+ ty:: Ref ( _, inner_ty, mutbl) if has_iter_method ( cx, inner_ty) . is_some ( ) => {
338+ let meth_name = match mutbl {
340339 Mutability :: Mut => "iter_mut" ,
341340 Mutability :: Not => "iter" ,
342341 } ;
342+ let caller = match & arg. kind {
343+ ExprKind :: AddrOf ( BorrowKind :: Ref , _, arg_inner) => arg_inner,
344+ _ => arg,
345+ } ;
343346 format ! (
344347 "{}.{}()" ,
345- sugg:: Sugg :: hir_with_applicability( cx, arg_inner , "_" , applic_ref) . maybe_par( ) ,
348+ sugg:: Sugg :: hir_with_applicability( cx, caller , "_" , applic_ref) . maybe_par( ) ,
346349 meth_name,
347350 )
348351 } ,
0 commit comments