]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
[rust.git] / src / test / ui / consts / const-eval / validate_uninhabited_zsts.rs
1 #![feature(const_fn)]
2 #![feature(const_fn_transmute)]
3
4 const fn foo() -> ! {
5     unsafe { std::mem::transmute(()) }
6     //~^ WARN any use of this value will cause an error [const_err]
7     //~| WARN the type `!` does not permit zero-initialization [invalid_value]
8     //~| WARN this was previously accepted by the compiler but is being phased out
9 }
10
11 #[derive(Clone, Copy)]
12 enum Empty { }
13
14 #[warn(const_err)]
15 const FOO: [Empty; 3] = [foo(); 3];
16
17 #[warn(const_err)]
18 const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
19 //~^ ERROR it is undefined behavior to use this value
20 //~| WARN the type `Empty` does not permit zero-initialization
21
22 fn main() {
23     FOO;
24     BAR;
25 }