]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/ub-ref.rs
Rollup merge of #56425 - scottmcm:redo-vec-set_len-docs, r=Centril
[rust.git] / src / test / ui / consts / const-eval / ub-ref.rs
1 #![feature(const_transmute)]
2 #![allow(const_err)] // make sure we cannot allow away the errors tested here
3
4 use std::mem;
5
6 const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
7 //~^ ERROR it is undefined behavior to use this value
8
9 const NULL: &u16 = unsafe { mem::transmute(0usize) };
10 //~^ ERROR it is undefined behavior to use this value
11
12 const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
13 //~^ ERROR it is undefined behavior to use this value
14
15 const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
16 //~^ ERROR it is undefined behavior to use this value
17
18 const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
19 //~^ ERROR it is undefined behavior to use this value
20
21 fn main() {}