rust/tests/ui/consts/extra-const-ub/detect-extra-ub.rs

32 lines
862 B
Rust
Raw Normal View History

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
#![feature(const_ptr_read)]
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
};
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
};
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
};
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
};
fn main() {}