Skip to content

Commit 013c2f3

Browse files
committed
Add some tests
1 parent f2eb9f8 commit 013c2f3

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed

tests/ui/rfc-2008-non-exhaustive/omitted-patterns.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use enums::{
1313
EmptyNonExhaustiveEnum, NestedNonExhaustive, NonExhaustiveEnum, NonExhaustiveSingleVariant,
1414
VariantNonExhaustive,
1515
};
16-
use unstable::{UnstableEnum, OnlyUnstableEnum, UnstableStruct, OnlyUnstableStruct};
1716
use structs::{FunctionalRecord, MixedVisFields, NestedStruct, NormalStruct};
17+
use unstable::{OnlyUnstableEnum, OnlyUnstableStruct, UnstableEnum, UnstableStruct};
1818

1919
#[non_exhaustive]
2020
#[derive(Default)]
@@ -127,11 +127,22 @@ fn main() {
127127
_ => {}
128128
}
129129

130+
// No variants are mentioned
130131
#[deny(non_exhaustive_omitted_patterns)]
131132
match NonExhaustiveSingleVariant::A(true) {
132133
_ => {}
133134
}
134135
//~^^ some variants are not matched explicitly
136+
#[deny(non_exhaustive_omitted_patterns)]
137+
match Some(NonExhaustiveSingleVariant::A(true)) {
138+
Some(_) => {}
139+
None => {}
140+
}
141+
#[deny(non_exhaustive_omitted_patterns)]
142+
match Some(&NonExhaustiveSingleVariant::A(true)) {
143+
Some(_) => {}
144+
None => {}
145+
}
135146

136147
// Ok: we don't lint on `if let` expressions
137148
#[deny(non_exhaustive_omitted_patterns)]
@@ -202,6 +213,25 @@ fn main() {
202213
_ => {}
203214
}
204215
//~^^ some variants are not matched explicitly
216+
217+
#[deny(non_exhaustive_omitted_patterns)]
218+
match (true, &non_enum) {
219+
(true, NonExhaustiveEnum::Unit) => {}
220+
_ => {}
221+
}
222+
223+
#[deny(non_exhaustive_omitted_patterns)]
224+
match (&non_enum, true) {
225+
(NonExhaustiveEnum::Unit, true) => {}
226+
_ => {}
227+
}
228+
//~^^ some variants are not matched explicitly
229+
230+
#[deny(non_exhaustive_omitted_patterns)]
231+
match Some(&non_enum) {
232+
Some(NonExhaustiveEnum::Unit | NonExhaustiveEnum::Tuple(_)) => {}
233+
_ => {}
234+
}
205235
}
206236

207237
#[deny(non_exhaustive_omitted_patterns)]

tests/ui/rfc-2008-non-exhaustive/omitted-patterns.stderr

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@ LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = Nested
5050
= note: the pattern is of type `NestedStruct` and the `non_exhaustive_omitted_patterns` attribute was found
5151

5252
warning: some fields are not explicitly listed
53-
--> $DIR/omitted-patterns.rs:173:9
53+
--> $DIR/omitted-patterns.rs:184:9
5454
|
5555
LL | let OnlyUnstableStruct { unstable, .. } = OnlyUnstableStruct::new();
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `unstable2` not listed
5757
|
5858
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
5959
= note: the pattern is of type `OnlyUnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
6060
note: the lint level is defined here
61-
--> $DIR/omitted-patterns.rs:172:12
61+
--> $DIR/omitted-patterns.rs:183:12
6262
|
6363
LL | #[warn(non_exhaustive_omitted_patterns)]
6464
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6565

6666
warning: some fields are not explicitly listed
67-
--> $DIR/omitted-patterns.rs:181:9
67+
--> $DIR/omitted-patterns.rs:192:9
6868
|
6969
LL | let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
7070
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `unstable` not listed
7171
|
7272
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
7373
= note: the pattern is of type `UnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
7474
note: the lint level is defined here
75-
--> $DIR/omitted-patterns.rs:180:12
75+
--> $DIR/omitted-patterns.rs:191:12
7676
|
7777
LL | #[warn(non_exhaustive_omitted_patterns)]
7878
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -143,49 +143,49 @@ LL | _ => {}
143143
= note: the matched value is of type `NestedNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
144144

145145
error: some variants are not matched explicitly
146-
--> $DIR/omitted-patterns.rs:132:9
146+
--> $DIR/omitted-patterns.rs:133:9
147147
|
148148
LL | _ => {}
149149
| ^ pattern `NonExhaustiveSingleVariant::A(_)` not covered
150150
|
151151
= help: ensure that all variants are matched explicitly by adding the suggested match arms
152152
= note: the matched value is of type `NonExhaustiveSingleVariant` and the `non_exhaustive_omitted_patterns` attribute was found
153153
note: the lint level is defined here
154-
--> $DIR/omitted-patterns.rs:130:12
154+
--> $DIR/omitted-patterns.rs:131:12
155155
|
156156
LL | #[deny(non_exhaustive_omitted_patterns)]
157157
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158158

159159
error: some variants are not matched explicitly
160-
--> $DIR/omitted-patterns.rs:144:9
160+
--> $DIR/omitted-patterns.rs:155:9
161161
|
162162
LL | _ => {}
163163
| ^ pattern `UnstableEnum::Unstable` not covered
164164
|
165165
= help: ensure that all variants are matched explicitly by adding the suggested match arms
166166
= note: the matched value is of type `UnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
167167
note: the lint level is defined here
168-
--> $DIR/omitted-patterns.rs:143:16
168+
--> $DIR/omitted-patterns.rs:154:16
169169
|
170170
LL | #[deny(non_exhaustive_omitted_patterns)]
171171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172172

173173
error: some variants are not matched explicitly
174-
--> $DIR/omitted-patterns.rs:168:9
174+
--> $DIR/omitted-patterns.rs:179:9
175175
|
176176
LL | _ => {}
177177
| ^ pattern `OnlyUnstableEnum::Unstable2` not covered
178178
|
179179
= help: ensure that all variants are matched explicitly by adding the suggested match arms
180180
= note: the matched value is of type `OnlyUnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
181181
note: the lint level is defined here
182-
--> $DIR/omitted-patterns.rs:165:12
182+
--> $DIR/omitted-patterns.rs:176:12
183183
|
184184
LL | #[deny(non_exhaustive_omitted_patterns)]
185185
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
186186

187187
error[E0005]: refutable pattern in local binding
188-
--> $DIR/omitted-patterns.rs:194:9
188+
--> $DIR/omitted-patterns.rs:205:9
189189
|
190190
LL | let local_refutable @ NonExhaustiveEnum::Unit = NonExhaustiveEnum::Unit;
191191
| ^^^^^^^^^^^^^^^ pattern `_` not covered
@@ -199,19 +199,33 @@ LL | let local_refutable @ NonExhaustiveEnum::Unit = NonExhaustiveEnum::Unit
199199
| ++++++++++++++++
200200

201201
error: some variants are not matched explicitly
202-
--> $DIR/omitted-patterns.rs:202:9
202+
--> $DIR/omitted-patterns.rs:213:9
203203
|
204204
LL | _ => {}
205205
| ^ pattern `NonExhaustiveEnum::Struct { .. }` not covered
206206
|
207207
= help: ensure that all variants are matched explicitly by adding the suggested match arms
208208
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
209209
note: the lint level is defined here
210-
--> $DIR/omitted-patterns.rs:198:12
210+
--> $DIR/omitted-patterns.rs:209:12
211211
|
212212
LL | #[deny(non_exhaustive_omitted_patterns)]
213213
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
214214

215-
error: aborting due to 10 previous errors; 6 warnings emitted
215+
error: some variants are not matched explicitly
216+
--> $DIR/omitted-patterns.rs:226:9
217+
|
218+
LL | _ => {}
219+
| ^ patterns `NonExhaustiveEnum::Tuple(_)` and `NonExhaustiveEnum::Struct { .. }` not covered
220+
|
221+
= help: ensure that all variants are matched explicitly by adding the suggested match arms
222+
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
223+
note: the lint level is defined here
224+
--> $DIR/omitted-patterns.rs:223:12
225+
|
226+
LL | #[deny(non_exhaustive_omitted_patterns)]
227+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
228+
229+
error: aborting due to 11 previous errors; 6 warnings emitted
216230

217231
For more information about this error, try `rustc --explain E0005`.

0 commit comments

Comments
 (0)