@@ -7,7 +7,7 @@ use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}
7
7
use rustc_hir:: { BinOpKind , BorrowKind , Expr , ExprKind , HirId , HirIdMap , Local , Mutability , Pat , PatKind , Stmt } ;
8
8
use rustc_lint:: LateContext ;
9
9
use rustc_middle:: hir:: nested_filter;
10
- use rustc_middle:: ty:: Ty ;
10
+ use rustc_middle:: ty:: { self , Ty } ;
11
11
use rustc_span:: source_map:: Spanned ;
12
12
use rustc_span:: symbol:: { sym, Symbol } ;
13
13
use rustc_typeck:: hir_ty_to_ty;
@@ -332,17 +332,20 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
332
332
} else {
333
333
// (&x).into_iter() ==> x.iter()
334
334
// (&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 {
340
339
Mutability :: Mut => "iter_mut" ,
341
340
Mutability :: Not => "iter" ,
342
341
} ;
342
+ let caller = match & arg. kind {
343
+ ExprKind :: AddrOf ( BorrowKind :: Ref , _, arg_inner) => arg_inner,
344
+ _ => arg,
345
+ } ;
343
346
format ! (
344
347
"{}.{}()" ,
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( ) ,
346
349
meth_name,
347
350
)
348
351
} ,
0 commit comments