]> git.proxmox.com Git - rustc.git/blame - src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / uninhabited / uninhabited-matches-feature-gated.rs
CommitLineData
dfeec247 1use std::mem::zeroed;
32a655c1
SL
2enum Void {}
3
4fn main() {
5 let x: Result<u32, &'static Void> = Ok(23);
6 let _ = match x { //~ ERROR non-exhaustive
7 Ok(n) => n,
8 };
9
dfeec247
XL
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() };
32a655c1
SL
15 let _ = match x {}; //~ ERROR non-exhaustive
16
dfeec247 17 let x: (Void,) = unsafe { zeroed() };
32a655c1
SL
18 let _ = match x {}; //~ ERROR non-exhaustive
19
dfeec247 20 let x: [Void; 1] = unsafe { zeroed() };
32a655c1
SL
21 let _ = match x {}; //~ ERROR non-exhaustive
22
dfeec247 23 let x: &[Void] = unsafe { zeroed() };
32a655c1
SL
24 let _ = match x { //~ ERROR non-exhaustive
25 &[] => (),
26 };
27
dfeec247 28 let x: Void = unsafe { zeroed() };
32a655c1
SL
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}