@@ -42,13 +42,13 @@ declare_clippy_lint! {
42
42
/// impl Copy for A {}
43
43
/// ```
44
44
#[ clippy:: version = "1.72.0" ]
45
- pub NEEDLESS_CLONE_IMPL ,
45
+ pub INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
46
46
correctness,
47
47
"manual implementation of `Clone` on a `Copy` type"
48
48
}
49
- declare_lint_pass ! ( NeedlessImpls => [ NEEDLESS_CLONE_IMPL ] ) ;
49
+ declare_lint_pass ! ( IncorrectImpls => [ INCORRECT_CLONE_IMPL_ON_COPY_TYPE ] ) ;
50
50
51
- impl LateLintPass < ' _ > for NeedlessImpls {
51
+ impl LateLintPass < ' _ > for IncorrectImpls {
52
52
#[ expect( clippy:: needless_return) ]
53
53
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & ImplItem < ' _ > ) {
54
54
let node = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) ;
@@ -77,7 +77,6 @@ impl LateLintPass<'_> for NeedlessImpls {
77
77
78
78
// Actual implementation; remove this comment once aforementioned PR is merged
79
79
if cx. tcx . is_diagnostic_item ( sym:: Clone , trait_impl_def_id)
80
- && impl_item. ident . name == sym:: clone
81
80
&& let Some ( copy_def_id) = cx. tcx . get_diagnostic_item ( sym:: Copy )
82
81
&& implements_trait (
83
82
cx,
@@ -86,20 +85,36 @@ impl LateLintPass<'_> for NeedlessImpls {
86
85
trait_impl. substs ,
87
86
)
88
87
{
89
- if block. stmts . is_empty ( )
90
- && let Some ( expr) = block. expr
91
- && let ExprKind :: Unary ( UnOp :: Deref , inner) = expr. kind
92
- && let ExprKind :: Path ( qpath) = inner. kind
93
- && last_path_segment ( & qpath) . ident . name == symbol:: kw:: SelfLower
94
- { } else {
88
+ if impl_item. ident . name == sym:: clone {
89
+ if block. stmts . is_empty ( )
90
+ && let Some ( expr) = block. expr
91
+ && let ExprKind :: Unary ( UnOp :: Deref , inner) = expr. kind
92
+ && let ExprKind :: Path ( qpath) = inner. kind
93
+ && last_path_segment ( & qpath) . ident . name == symbol:: kw:: SelfLower
94
+ { } else {
95
+ span_lint_and_sugg (
96
+ cx,
97
+ INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
98
+ block. span ,
99
+ "incorrect implementation of `clone` on a `Copy` type" ,
100
+ "change this to" ,
101
+ "{ *self }" . to_owned ( ) ,
102
+ Applicability :: MaybeIncorrect ,
103
+ ) ;
104
+
105
+ return ;
106
+ }
107
+ }
108
+
109
+ if impl_item. ident . name == sym:: clone_from {
95
110
span_lint_and_sugg (
96
111
cx,
97
- NEEDLESS_CLONE_IMPL ,
98
- block . span ,
99
- "manual implementation of `Clone ` on a `Copy` type" ,
100
- "change this to " ,
101
- "{ *self }" . to_owned ( ) ,
102
- Applicability :: Unspecified ,
112
+ INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
113
+ impl_item . span ,
114
+ "incorrect implementation of `clone_from ` on a `Copy` type" ,
115
+ "remove this" ,
116
+ String :: new ( ) ,
117
+ Applicability :: MaybeIncorrect ,
103
118
) ;
104
119
105
120
return ;
0 commit comments