@@ -514,8 +514,7 @@ impl LateLintPass for Pass {
514
514
515
515
let self_ty = cx. tcx . expr_ty_adjusted ( & args[ 0 ] ) ;
516
516
if args. len ( ) == 1 && name. node . as_str ( ) == "clone" {
517
- lint_clone_on_copy ( cx, expr) ;
518
- lint_clone_double_ref ( cx, expr, & args[ 0 ] , self_ty) ;
517
+ lint_clone_on_copy ( cx, expr, & args[ 0 ] , self_ty) ;
519
518
}
520
519
521
520
match self_ty. sty {
@@ -703,19 +702,11 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hi
703
702
}
704
703
705
704
/// Checks for the `CLONE_ON_COPY` lint.
706
- fn lint_clone_on_copy ( cx : & LateContext , expr : & hir:: Expr ) {
705
+ fn lint_clone_on_copy ( cx : & LateContext , expr : & hir:: Expr , arg : & hir :: Expr , arg_ty : ty :: Ty ) {
707
706
let ty = cx. tcx . expr_ty ( expr) ;
708
707
let parent = cx. tcx . map . get_parent ( expr. id ) ;
709
708
let parameter_environment = ty:: ParameterEnvironment :: for_item ( cx. tcx , parent) ;
710
-
711
- if !ty. moves_by_default ( cx. tcx . global_tcx ( ) , & parameter_environment, expr. span ) {
712
- span_lint ( cx, CLONE_ON_COPY , expr. span , "using `clone` on a `Copy` type" ) ;
713
- }
714
- }
715
-
716
- /// Checks for the `CLONE_DOUBLE_REF` lint.
717
- fn lint_clone_double_ref ( cx : & LateContext , expr : & hir:: Expr , arg : & hir:: Expr , ty : ty:: Ty ) {
718
- if let ty:: TyRef ( _, ty:: TypeAndMut { ty : inner, .. } ) = ty. sty {
709
+ if let ty:: TyRef ( _, ty:: TypeAndMut { ty : inner, .. } ) = arg_ty. sty {
719
710
if let ty:: TyRef ( ..) = inner. sty {
720
711
span_lint_and_then ( cx,
721
712
CLONE_DOUBLE_REF ,
@@ -725,8 +716,23 @@ fn lint_clone_double_ref(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, ty
725
716
|db| if let Some ( snip) = sugg:: Sugg :: hir_opt ( cx, arg) {
726
717
db. span_suggestion ( expr. span , "try dereferencing it" , format ! ( "({}).clone()" , snip. deref( ) ) ) ;
727
718
} ) ;
719
+ return ; // don't report clone_on_copy
728
720
}
729
721
}
722
+
723
+ if !ty. moves_by_default ( cx. tcx . global_tcx ( ) , & parameter_environment, expr. span ) {
724
+ span_lint_and_then ( cx,
725
+ CLONE_ON_COPY ,
726
+ expr. span ,
727
+ "using `clone` on a `Copy` type" ,
728
+ |db| if let Some ( snip) = sugg:: Sugg :: hir_opt ( cx, arg) {
729
+ if let ty:: TyRef ( ..) = cx. tcx . expr_ty ( arg) . sty {
730
+ db. span_suggestion ( expr. span , "try dereferencing it" , format ! ( "{}" , snip. deref( ) ) ) ;
731
+ } else {
732
+ db. span_suggestion ( expr. span , "try removing the `clone` call" , format ! ( "{}" , snip) ) ;
733
+ }
734
+ } ) ;
735
+ }
730
736
}
731
737
732
738
fn lint_extend ( cx : & LateContext , expr : & hir:: Expr , args : & MethodArgs ) {
0 commit comments