Skip to content

Commit 3d83ff6

Browse files
committed
Add ui test for empty fields for omitted_patterns lint
1 parent f7a8980 commit 3d83ff6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/test/ui/rfc-2008-non-exhaustive/auxiliary/structs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ pub struct NestedStruct {
3131
pub foo: u16,
3232
pub bar: NormalStruct,
3333
}
34+
35+
#[derive(Default)]
36+
#[non_exhaustive]
37+
pub struct MixedVisFields {
38+
pub a: u16,
39+
pub b: bool,
40+
pub(crate) foo: bool,
41+
}

src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use enums::{
1010
EmptyNonExhaustiveEnum, NestedNonExhaustive, NonExhaustiveEnum, NonExhaustiveSingleVariant,
1111
VariantNonExhaustive,
1212
};
13-
use structs::{FunctionalRecord, NestedStruct, NormalStruct};
13+
use structs::{FunctionalRecord, MixedVisFields, NestedStruct, NormalStruct};
1414

1515
#[non_exhaustive]
1616
#[derive(Default)]
@@ -141,6 +141,10 @@ fn main() {
141141
//~^ some fields are not explicitly listed
142142
//~^^ some fields are not explicitly listed
143143

144+
// Ok: this tests https://github.com/rust-lang/rust/issues/89382
145+
#[warn(non_exhaustive_omitted_patterns)]
146+
let MixedVisFields { a, b, .. } = MixedVisFields::default();
147+
144148
// Ok: because this only has 1 variant
145149
#[deny(non_exhaustive_omitted_patterns)]
146150
match NonExhaustiveSingleVariant::A(true) {

src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ LL | #[deny(non_exhaustive_omitted_patterns)]
129129
= note: the matched value is of type `ErrorKind` and the `non_exhaustive_omitted_patterns` attribute was found
130130

131131
error: some variants are not matched explicitly
132-
--> $DIR/reachable-patterns.rs:153:9
132+
--> $DIR/reachable-patterns.rs:157:9
133133
|
134134
LL | _ => {}
135135
| ^ pattern `A(_)` not covered
136136
|
137137
note: the lint level is defined here
138-
--> $DIR/reachable-patterns.rs:151:12
138+
--> $DIR/reachable-patterns.rs:155:12
139139
|
140140
LL | #[deny(non_exhaustive_omitted_patterns)]
141141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)