]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsafe/union_destructure.rs
Rollup merge of #103033 - alyssais:pkg-config, r=joshtriplett
[rust.git] / src / test / ui / unsafe / union_destructure.rs
1 // run-pass
2 // revisions: mir thir
3 // [thir]compile-flags: -Z thir-unsafeck
4
5 #[derive(Copy, Clone)]
6 #[allow(dead_code)]
7 struct Pie {
8     slices: u8,
9     size: u8,
10 }
11
12 union Foo {
13     #[allow(dead_code)]
14     bar: i8,
15     baz: Pie
16 }
17
18 fn main() {
19     let u = Foo { bar: 5 };
20     let (Some(Foo { bar: _ }) | None) = Some(u);
21     let u = Foo { bar: 6 };
22     let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u);
23     unsafe {
24         let u = Foo { bar: 7 };
25         let (Foo { bar } | Foo { bar }) = u;
26         assert_eq!(bar, 7)
27     }
28     let u = Foo { bar: 8 };
29     match Some(u) {
30         Some(Foo { bar: _ }) => 3,
31         None => 4,
32     };
33
34     let u = Foo { bar: 9 };
35     unsafe { //[mir]~ WARNING unnecessary `unsafe` block
36         match u {
37             Foo { baz: Pie { .. } } => {},
38         };
39     }
40     let u = Foo { bar: 10 };
41     unsafe { //[mir]~ WARNING unnecessary `unsafe` block
42         match u {
43             Foo { baz: Pie { slices: _, size: _ } } => {},
44         };
45     }
46
47     let u = Foo { bar: 11 };
48     match u {
49         Foo { baz: _ } => {},
50     };
51 }