]> git.lizzy.rs Git - rust.git/blob - src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs
Rollup merge of #88780 - orlp:int-abs-diff, r=m-ou-se
[rust.git] / src / test / ui / uninhabited / uninhabited-matches-feature-gated.rs
1 use std::mem::zeroed;
2 enum Void {}
3
4 fn main() {
5     let x: Result<u32, &'static Void> = Ok(23);
6     let _ = match x {   //~ ERROR non-exhaustive
7         Ok(n) => n,
8     };
9
10     // This is pretty much instant UB. However, we have no choice -- we need to
11     // test matching on a reference to `&Void`; we cannot do anything other than
12     // just accept the fact that this is UB if `main` did run, but it doesn't;
13     // this test only checks that these are feature-gated.
14     let x: &Void = unsafe { zeroed() };
15     let _ = match x {}; //~ ERROR non-exhaustive
16
17     let x: (Void,) = unsafe { zeroed() };
18     let _ = match x {}; //~ ERROR non-exhaustive
19
20     let x: [Void; 1] = unsafe { zeroed() };
21     let _ = match x {}; //~ ERROR non-exhaustive
22
23     let x: &[Void] = unsafe { zeroed() };
24     let _ = match x {   //~ ERROR non-exhaustive
25         &[] => (),
26     };
27
28     let x: Void = unsafe { zeroed() };
29     let _ = match x {}; // okay
30
31     let x: Result<u32, Void> = Ok(23);
32     let _ = match x {   //~ ERROR non-exhaustive
33         Ok(x) => x,
34     };
35
36     let x: Result<u32, Void> = Ok(23);
37     let Ok(x) = x;
38     //~^ ERROR refutable
39 }