]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.rs
parser will not give wrong help message for 'public'
[rust.git] / src / test / ui / rfc-2008-non-exhaustive / stable-omitted-patterns.rs
1 // Test that the `non_exhaustive_omitted_patterns` lint is triggered correctly with variants
2 // marked stable and unstable.
3
4 #![feature(non_exhaustive_omitted_patterns_lint)]
5
6 // aux-build:unstable.rs
7 extern crate unstable;
8
9 use unstable::{UnstableEnum, OnlyUnstableEnum, UnstableStruct, OnlyUnstableStruct};
10
11 fn main() {
12     // OK: this matches all the stable variants
13     match UnstableEnum::Stable {
14         UnstableEnum::Stable => {}
15         UnstableEnum::Stable2 => {}
16         #[deny(non_exhaustive_omitted_patterns)]
17         _ => {}
18     }
19
20     match UnstableEnum::Stable {
21         UnstableEnum::Stable => {}
22         #[deny(non_exhaustive_omitted_patterns)]
23         _ => {}
24     }
25     //~^^ some variants are not matched explicitly
26
27     // Ok: although this is a bit odd, we don't have anything to report
28     // since there is no stable variants and the feature is off
29     #[deny(non_exhaustive_omitted_patterns)]
30     match OnlyUnstableEnum::new() {
31         _ => {}
32     }
33
34     // Ok: Same as the above enum (no fields can be matched on)
35     #[warn(non_exhaustive_omitted_patterns)]
36     let OnlyUnstableStruct { .. } = OnlyUnstableStruct::new();
37
38     #[warn(non_exhaustive_omitted_patterns)]
39     let UnstableStruct { stable, .. } = UnstableStruct::default();
40     //~^ some fields are not explicitly listed
41
42     // OK: stable field is matched
43     #[warn(non_exhaustive_omitted_patterns)]
44     let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
45 }