]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/ub-ref.rs
Rollup merge of #59880 - solson:transmute-float, r=alexcrichton
[rust.git] / src / test / ui / consts / const-eval / ub-ref.rs
1 // ignore-tidy-linelength
2 #![feature(const_transmute)]
3 #![allow(const_err)] // make sure we cannot allow away the errors tested here
4
5 use std::mem;
6
7 const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
8 //~^ ERROR it is undefined behavior to use this value
9 //~^^ type validation failed: encountered unaligned reference (required 2 byte alignment but found 1)
10
11 const NULL: &u16 = unsafe { mem::transmute(0usize) };
12 //~^ ERROR it is undefined behavior to use this value
13
14 const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
15 //~^ ERROR it is undefined behavior to use this value
16
17 const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
18 //~^ ERROR it is undefined behavior to use this value
19
20 const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
21 //~^ ERROR it is undefined behavior to use this value
22
23 fn main() {}