@@ -14,11 +14,12 @@ use rustc_span::symbol::kw;
14
14
15
15
declare_clippy_lint ! {
16
16
/// ### What it does
17
- /// Checks for manual implementations of `Clone` when `Copy` is already implemented.
17
+ /// Checks for non-canonical implementations of `Clone` when `Copy` is already implemented.
18
18
///
19
19
/// ### Why is this bad?
20
- /// If both `Clone` and `Copy` are implemented, they must agree. This is done by dereferencing
21
- /// `self` in `Clone`'s implementation. Anything else is incorrect.
20
+ /// If both `Clone` and `Copy` are implemented, they must agree. This can done by dereferencing
21
+ /// `self` in `Clone`'s implementation, which will avoid any possibility of the implementations
22
+ /// becoming out of sync.
22
23
///
23
24
/// ### Example
24
25
/// ```rust,ignore
@@ -47,26 +48,22 @@ declare_clippy_lint! {
47
48
/// impl Copy for A {}
48
49
/// ```
49
50
#[ clippy:: version = "1.72.0" ]
50
- pub INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
51
- correctness ,
52
- "manual implementation of `Clone` on a `Copy` type"
51
+ pub NON_CANONICAL_CLONE_IMPL ,
52
+ suspicious ,
53
+ "non-canonical implementation of `Clone` on a `Copy` type"
53
54
}
54
55
declare_clippy_lint ! {
55
56
/// ### What it does
56
- /// Checks for manual implementations of both `PartialOrd` and `Ord` when only `Ord` is
57
- /// necessary.
57
+ /// Checks for non-canonical implementations of `PartialOrd` when `Ord` is already implemented.
58
58
///
59
59
/// ### Why is this bad?
60
60
/// If both `PartialOrd` and `Ord` are implemented, they must agree. This is commonly done by
61
61
/// wrapping the result of `cmp` in `Some` for `partial_cmp`. Not doing this may silently
62
62
/// introduce an error upon refactoring.
63
63
///
64
64
/// ### Known issues
65
- /// Code that calls the `.into()` method instead will be flagged as incorrect, despite `.into()`
66
- /// wrapping it in `Some`.
67
- ///
68
- /// ### Limitations
69
- /// Will not lint if `Self` and `Rhs` do not have the same type.
65
+ /// Code that calls the `.into()` method instead will be flagged, despite `.into()` wrapping it
66
+ /// in `Some`.
70
67
///
71
68
/// ### Example
72
69
/// ```rust
@@ -108,13 +105,13 @@ declare_clippy_lint! {
108
105
/// }
109
106
/// ```
110
107
#[ clippy:: version = "1.72.0" ]
111
- pub INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ,
112
- correctness ,
113
- "manual implementation of `PartialOrd` when `Ord` is already implemented "
108
+ pub NON_CANONICAL_PARTIAL_ORD_IMPL ,
109
+ suspicious ,
110
+ "non-canonical implementation of `PartialOrd` on an `Ord` type "
114
111
}
115
- declare_lint_pass ! ( IncorrectImpls => [ INCORRECT_CLONE_IMPL_ON_COPY_TYPE , INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ] ) ;
112
+ declare_lint_pass ! ( NonCanonicalImpls => [ NON_CANONICAL_CLONE_IMPL , NON_CANONICAL_PARTIAL_ORD_IMPL ] ) ;
116
113
117
- impl LateLintPass < ' _ > for IncorrectImpls {
114
+ impl LateLintPass < ' _ > for NonCanonicalImpls {
118
115
#[ expect( clippy:: too_many_lines) ]
119
116
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & ImplItem < ' _ > ) {
120
117
let Some ( Node :: Item ( item) ) = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) else {
@@ -155,9 +152,9 @@ impl LateLintPass<'_> for IncorrectImpls {
155
152
{ } else {
156
153
span_lint_and_sugg (
157
154
cx,
158
- INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
155
+ NON_CANONICAL_CLONE_IMPL ,
159
156
block. span ,
160
- "incorrect implementation of `clone` on a `Copy` type" ,
157
+ "non-canonical implementation of `clone` on a `Copy` type" ,
161
158
"change this to" ,
162
159
"{ *self }" . to_owned ( ) ,
163
160
Applicability :: MaybeIncorrect ,
@@ -170,9 +167,9 @@ impl LateLintPass<'_> for IncorrectImpls {
170
167
if impl_item. ident . name == sym:: clone_from {
171
168
span_lint_and_sugg (
172
169
cx,
173
- INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
170
+ NON_CANONICAL_CLONE_IMPL ,
174
171
impl_item. span ,
175
- "incorrect implementation of `clone_from` on a `Copy` type" ,
172
+ "unnecessary implementation of `clone_from` on a `Copy` type" ,
176
173
"remove it" ,
177
174
String :: new ( ) ,
178
175
Applicability :: MaybeIncorrect ,
@@ -218,9 +215,9 @@ impl LateLintPass<'_> for IncorrectImpls {
218
215
219
216
span_lint_and_then (
220
217
cx,
221
- INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ,
218
+ NON_CANONICAL_PARTIAL_ORD_IMPL ,
222
219
item. span ,
223
- "incorrect implementation of `partial_cmp` on an `Ord` type" ,
220
+ "non-canonical implementation of `partial_cmp` on an `Ord` type" ,
224
221
|diag| {
225
222
let [ _, other] = body. params else {
226
223
return ;
0 commit comments