Skip to content

Commit ff923b0

Browse files
committed
Do not lint never-like enums
1 parent 53d9f64 commit ff923b0

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

clippy_lints/src/incorrect_impls.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ impl LateLintPass<'_> for IncorrectImpls {
161161
// `MaybeUninit<T>`
162162
ty::Adt(_, _) if is_type_lang_item(cx, ty, LangItem::MaybeUninit) => true,
163163
// `[MaybeUninit<T>; N]`
164-
ty::Array(inner_ty, _) | ty::Slice(inner_ty)
165-
if is_type_lang_item(cx, *inner_ty, LangItem::MaybeUninit) =>
166-
{
167-
true
164+
ty::Array(inner_ty, _) | ty::Slice(inner_ty) => {
165+
is_type_lang_item(cx, *inner_ty, LangItem::MaybeUninit)
168166
},
169167
// Other cases are likely pretty rare.
170168
_ => false,
@@ -174,6 +172,11 @@ impl LateLintPass<'_> for IncorrectImpls {
174172
return;
175173
}
176174

175+
// Skip `never`-like enums
176+
if def.is_enum() && def.variants().is_empty() {
177+
return;
178+
}
179+
177180
if impl_item.ident.name == sym::clone {
178181
if block.stmts.is_empty()
179182
&& let Some(expr) = block.expr

tests/ui/incorrect_clone_impl_on_copy_type.fixed

+14-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ impl<A: Copy> Clone for Uwu<A> {
9696

9797
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
9898

99-
// do not lint if type has only `MaybeUninit` fields
99+
// do not lint if type has only `MaybeUninit` fields, #11072
100+
100101
struct G([std::mem::MaybeUninit<u32>; 100]);
101102

102103
impl Clone for G {
@@ -106,3 +107,15 @@ impl Clone for G {
106107
}
107108

108109
impl Copy for G {}
110+
111+
// do not lint `never`-like enums, #11071
112+
113+
enum H {}
114+
115+
impl Clone for H {
116+
fn clone(&self) -> Self {
117+
todo!()
118+
}
119+
}
120+
121+
impl Copy for H {}

tests/ui/incorrect_clone_impl_on_copy_type.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl<A: Copy> Clone for Uwu<A> {
106106

107107
impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
108108

109-
// do not lint if type has only `MaybeUninit` fields
109+
// do not lint if type has only `MaybeUninit` fields, #11072
110+
110111
struct G([std::mem::MaybeUninit<u32>; 100]);
111112

112113
impl Clone for G {
@@ -116,3 +117,15 @@ impl Clone for G {
116117
}
117118

118119
impl Copy for G {}
120+
121+
// do not lint `never`-like enums, #11071
122+
123+
enum H {}
124+
125+
impl Clone for H {
126+
fn clone(&self) -> Self {
127+
todo!()
128+
}
129+
}
130+
131+
impl Copy for H {}

0 commit comments

Comments
 (0)