@@ -42,13 +42,13 @@ declare_clippy_lint! {
4242 /// impl Copy for A {}
4343 /// ```
4444 #[ clippy:: version = "1.72.0" ]
45- pub NEEDLESS_CLONE_IMPL ,
45+ pub INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
4646 correctness,
4747 "manual implementation of `Clone` on a `Copy` type"
4848}
49- declare_lint_pass ! ( NeedlessImpls => [ NEEDLESS_CLONE_IMPL ] ) ;
49+ declare_lint_pass ! ( IncorrectImpls => [ INCORRECT_CLONE_IMPL_ON_COPY_TYPE ] ) ;
5050
51- impl LateLintPass < ' _ > for NeedlessImpls {
51+ impl LateLintPass < ' _ > for IncorrectImpls {
5252 #[ expect( clippy:: needless_return) ]
5353 fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & ImplItem < ' _ > ) {
5454 let node = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) ;
@@ -77,7 +77,6 @@ impl LateLintPass<'_> for NeedlessImpls {
7777
7878 // Actual implementation; remove this comment once aforementioned PR is merged
7979 if cx. tcx . is_diagnostic_item ( sym:: Clone , trait_impl_def_id)
80- && impl_item. ident . name == sym:: clone
8180 && let Some ( copy_def_id) = cx. tcx . get_diagnostic_item ( sym:: Copy )
8281 && implements_trait (
8382 cx,
@@ -86,20 +85,36 @@ impl LateLintPass<'_> for NeedlessImpls {
8685 trait_impl. substs ,
8786 )
8887 {
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 {
95110 span_lint_and_sugg (
96111 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 ,
103118 ) ;
104119
105120 return ;
0 commit comments