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