@@ -8,6 +8,7 @@ use rustc_hir as hir;
88use rustc_lint:: { LateContext , LateLintPass } ;
99use rustc_middle:: mir:: Mutability ;
1010use rustc_middle:: ty;
11+ use rustc_middle:: ty:: adjustment:: Adjust ;
1112use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1213use rustc_span:: symbol:: Ident ;
1314use rustc_span:: { sym, Span } ;
@@ -75,11 +76,14 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
7576 }
7677 }
7778 } ,
78- hir:: ExprKind :: MethodCall ( ref method, _, ref obj, _) => {
79- if ident_eq( name, & obj[ 0 ] ) && method. ident. as_str( ) == "clone"
80- && match_trait_method( cx, closure_expr, & paths:: CLONE_TRAIT ) {
81-
82- let obj_ty = cx. typeck_results( ) . expr_ty( & obj[ 0 ] ) ;
79+ hir:: ExprKind :: MethodCall ( ref method, _, [ obj] , _) => if_chain! {
80+ if ident_eq( name, obj) && method. ident. name == sym:: clone;
81+ if match_trait_method( cx, closure_expr, & paths:: CLONE_TRAIT ) ;
82+ // no autoderefs
83+ if !cx. typeck_results( ) . expr_adjustments( obj) . iter( )
84+ . any( |a| matches!( a. kind, Adjust :: Deref ( Some ( ..) ) ) ) ;
85+ then {
86+ let obj_ty = cx. typeck_results( ) . expr_ty( obj) ;
8387 if let ty:: Ref ( _, ty, mutability) = obj_ty. kind( ) {
8488 if matches!( mutability, Mutability :: Not ) {
8589 let copy = is_copy( cx, ty) ;
0 commit comments