Skip to content

Commit 739f273

Browse files
committed
Do not apply rest_pat_in_fully_bound_structs on #[non_exhaustive] structs
1 parent bc069ef commit 739f273

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
1414
if let ty::Adt(def, _) = ty.kind();
1515
if def.is_struct() || def.is_union();
1616
if fields.len() == def.non_enum_variant().fields.len();
17+
if !def.non_enum_variant().is_field_list_non_exhaustive();
1718

1819
then {
1920
span_lint_and_help(

tests/ui/rest_pat_in_fully_bound_structs.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,19 @@ fn main() {
3939

4040
// No lint
4141
foo!(a_struct);
42+
43+
#[non_exhaustive]
44+
struct B {
45+
a: u32,
46+
b: u32,
47+
c: u64,
48+
}
49+
50+
let b_struct = B { a: 5, b: 42, c: 342 };
51+
52+
match b_struct {
53+
B { a: 5, b: 42, .. } => {},
54+
B { a: 0, b: 0, c: 128, .. } => {}, // No Lint
55+
_ => {},
56+
}
4257
}

0 commit comments

Comments
 (0)