]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-46845.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-46845.rs
1 // run-pass
2 // To work around #46855
3 // compile-flags: -Z mir-opt-level=0
4 // Regression test for the inhabitedness of unions with uninhabited variants, issue #46845
5
6 use std::mem;
7
8 #[derive(Copy, Clone)]
9 enum Never { }
10
11 // A single uninhabited variant shouldn't make the whole union uninhabited.
12 union Foo {
13 a: u64,
14 _b: Never
15 }
16
17 // If all the variants are uninhabited, however, the union should be uninhabited.
18 // NOTE(#49298) the union being uninhabited shouldn't change its size.
19 union Bar {
20 _a: (Never, u64),
21 _b: (u64, Never)
22 }
23
24 fn main() {
25 assert_eq!(mem::size_of::<Foo>(), 8);
26 // See the note on `Bar`'s definition for why this isn't `0`.
27 assert_eq!(mem::size_of::<Bar>(), 8);
28
29 let f = [Foo { a: 42 }, Foo { a: 10 }];
30 println!("{}", unsafe { f[0].a });
31 assert_eq!(unsafe { f[1].a }, 10);
32 }