]> git.proxmox.com Git - rustc.git/blob - src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / src / test / 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 #[warn(const_err)]
20 const FOO: [empty::Empty; 3] = [foo(); 3];
21
22 #[warn(const_err)]
23 const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
24 //~^ ERROR it is undefined behavior to use this value
25 //~| WARN the type `empty::Empty` does not permit zero-initialization
26
27 fn main() {
28 FOO;
29 BAR;
30 }