2022-08-09 08:40:44 -05:00
|
|
|
// revisions: no_flag with_flag
|
2022-11-20 02:54:45 -06:00
|
|
|
// [no_flag] check-pass
|
2022-08-09 08:40:44 -05:00
|
|
|
// [with_flag] compile-flags: -Zextra-const-ub-checks
|
2022-08-07 07:30:03 -05:00
|
|
|
|
|
|
|
use std::mem::transmute;
|
|
|
|
|
|
|
|
const INVALID_BOOL: () = unsafe {
|
|
|
|
let _x: bool = transmute(3u8);
|
2022-08-09 08:40:44 -05:00
|
|
|
//[with_flag]~^ ERROR: evaluation of constant value failed
|
|
|
|
//[with_flag]~| invalid value
|
2022-08-07 07:30:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const INVALID_PTR_IN_INT: () = unsafe {
|
|
|
|
let _x: usize = transmute(&3u8);
|
2022-09-21 06:05:20 -05:00
|
|
|
//[with_flag]~^ ERROR: evaluation of constant value failed
|
2022-08-07 07:30:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const INVALID_SLICE_TO_USIZE_TRANSMUTE: () = unsafe {
|
|
|
|
let x: &[u8] = &[0; 32];
|
|
|
|
let _x: (usize, usize) = transmute(x);
|
2022-09-21 06:05:20 -05:00
|
|
|
//[with_flag]~^ ERROR: evaluation of constant value failed
|
2022-08-07 07:30:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const UNALIGNED_PTR: () = unsafe {
|
|
|
|
let _x: &u32 = transmute(&[0u8; 4]);
|
2022-08-09 08:40:44 -05:00
|
|
|
//[with_flag]~^ ERROR: evaluation of constant value failed
|
|
|
|
//[with_flag]~| invalid value
|
2022-08-07 07:30:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {}
|