]> git.proxmox.com Git - rustc.git/blob - tests/ui/consts/const-eval/validate_uninhabited_zsts.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / tests / ui / consts / const-eval / validate_uninhabited_zsts.rs
1 // stderr-per-bitwidth
2
3 const fn foo() -> ! {
4 unsafe { std::mem::transmute(()) }
5 //~^ ERROR evaluation of constant value failed
6 //~| WARN the type `!` does not permit zero-initialization [invalid_value]
7 }
8
9 // Type defined in a submodule, so that it is not "visibly"
10 // uninhabited (which would change interpreter behavior).
11 pub mod empty {
12 #[derive(Clone, Copy)]
13 enum Void {}
14
15 #[derive(Clone, Copy)]
16 pub struct Empty(Void);
17 }
18
19 const FOO: [empty::Empty; 3] = [foo(); 3];
20
21 const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
22 //~^ ERROR evaluation of constant value failed
23 //~| WARN the type `empty::Empty` does not permit zero-initialization
24
25 fn main() {
26 FOO;
27 BAR;
28 }