]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-46845.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // To work around #46855
12 // compile-flags: -Z mir-opt-level=0
13 // Regression test for the inhabitedness of unions with uninhabited variants, issue #46845
17 #[derive(Copy, Clone)]
20 // A single uninhabited variant shouldn't make the whole union uninhabited.
26 // If all the variants are uninhabited, however, the union should be uninhabited.
27 // NOTE(#49298) the union being uninhabited shouldn't change its size.
34 assert_eq
!(mem
::size_of
::<Foo
>(), 8);
35 // See the note on `Bar`'s definition for why this isn't `0`.
36 assert_eq
!(mem
::size_of
::<Bar
>(), 8);
38 let f
= [Foo { a: 42 }
, Foo { a: 10 }
];
39 println
!("{}", unsafe { f[0].a }
);
40 assert_eq
!(unsafe { f[1].a }
, 10);