]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/match_non_exhaustive.rs
Merge commit '57b3c4b90f4346b3990c1be387c3b3ca7b78412c' into clippyup
[rust.git] / src / test / ui / match / match_non_exhaustive.rs
1 // aux-build:match_non_exhaustive_lib.rs
2
3 /* The error message for non-exhaustive matches on non-local enums
4  * marked as non-exhaustive should mention the fact that the enum
5  * is marked as non-exhaustive (issue #85227).
6  */
7
8 // Ignore non_exhaustive in the same crate
9 #[non_exhaustive]
10 enum L { A, B }
11
12 extern crate match_non_exhaustive_lib;
13 use match_non_exhaustive_lib::{E1, E2};
14
15 fn foo() -> L {todo!()}
16 fn bar() -> (E1, E2) {todo!()}
17
18 fn main() {
19     let l = foo();
20     // No error for enums defined in this crate
21     match l { L::A => (), L::B => () };
22     // (except if the match is already non-exhaustive)
23     match l { L::A => () };
24     //~^ ERROR: non-exhaustive patterns: `B` not covered [E0004]
25
26     // E1 is not visibly uninhabited from here
27     let (e1, e2) = bar();
28     match e1 {};
29     //~^ ERROR: non-exhaustive patterns: type `E1` is non-empty [E0004]
30     match e2 { E2::A => (), E2::B => () };
31     //~^ ERROR: non-exhaustive patterns: `_` not covered [E0004]
32 }