Skip to content

Commit 0414bf9

Browse files
committed
fix: exhaustive_structs FP on structs with default valued field
1 parent 9e7782b commit 0414bf9

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

clippy_lints/src/exhaustive_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7676
"exported enums should not be exhaustive",
7777
[].as_slice(),
7878
),
79-
ItemKind::Struct(_, v, ..) => (
79+
ItemKind::Struct(_, v, ..) if v.fields().iter().all(|f| f.default.is_none()) => (
8080
EXHAUSTIVE_STRUCTS,
8181
"exported structs should not be exhaustive",
8282
v.fields(),

tests/ui/exhaustive_items.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(default_field_values)]
12
#![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
23
#![allow(unused)]
34

@@ -90,3 +91,9 @@ pub mod structs {
9091
pub bar: String,
9192
}
9293
}
94+
95+
pub mod issue14992 {
96+
pub struct A {
97+
pub a: isize = 42,
98+
}
99+
}

tests/ui/exhaustive_items.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(default_field_values)]
12
#![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
23
#![allow(unused)]
34

@@ -87,3 +88,9 @@ pub mod structs {
8788
pub bar: String,
8889
}
8990
}
91+
92+
pub mod issue14992 {
93+
pub struct A {
94+
pub a: isize = 42,
95+
}
96+
}

tests/ui/exhaustive_items.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: exported enums should not be exhaustive
2-
--> tests/ui/exhaustive_items.rs:9:5
2+
--> tests/ui/exhaustive_items.rs:10:5
33
|
44
LL | / pub enum Exhaustive {
55
LL | |
@@ -11,7 +11,7 @@ LL | | }
1111
| |_____^
1212
|
1313
note: the lint level is defined here
14-
--> tests/ui/exhaustive_items.rs:1:9
14+
--> tests/ui/exhaustive_items.rs:2:9
1515
|
1616
LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL ~ pub enum Exhaustive {
2222
|
2323

2424
error: exported enums should not be exhaustive
25-
--> tests/ui/exhaustive_items.rs:19:5
25+
--> tests/ui/exhaustive_items.rs:20:5
2626
|
2727
LL | / pub enum ExhaustiveWithAttrs {
2828
LL | |
@@ -40,7 +40,7 @@ LL ~ pub enum ExhaustiveWithAttrs {
4040
|
4141

4242
error: exported structs should not be exhaustive
43-
--> tests/ui/exhaustive_items.rs:55:5
43+
--> tests/ui/exhaustive_items.rs:56:5
4444
|
4545
LL | / pub struct Exhaustive {
4646
LL | |
@@ -50,7 +50,7 @@ LL | | }
5050
| |_____^
5151
|
5252
note: the lint level is defined here
53-
--> tests/ui/exhaustive_items.rs:1:35
53+
--> tests/ui/exhaustive_items.rs:2:35
5454
|
5555
LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)