@@ -8,6 +8,7 @@ use rustc_hir as hir;
8
8
use rustc_lint:: { LateContext , LateLintPass } ;
9
9
use rustc_middle:: mir:: Mutability ;
10
10
use rustc_middle:: ty;
11
+ use rustc_middle:: ty:: adjustment:: Adjust ;
11
12
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
12
13
use rustc_span:: symbol:: Ident ;
13
14
use rustc_span:: { sym, Span } ;
@@ -75,11 +76,14 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
75
76
}
76
77
}
77
78
} ,
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
+ let obj_ty = cx. typeck_results( ) . expr_ty( obj) ;
86
+ then {
83
87
if let ty:: Ref ( _, ty, _) = obj_ty. kind( ) {
84
88
let copy = is_copy( cx, ty) ;
85
89
lint( cx, e. span, args[ 0 ] . span, copy) ;
0 commit comments