2018-10-17 09:55:59 -05:00
|
|
|
#[repr(u32)]
|
2020-09-20 05:02:04 -05:00
|
|
|
#[derive(Debug)]
|
2022-06-21 13:38:02 -05:00
|
|
|
enum Bool {
|
|
|
|
True,
|
|
|
|
}
|
2018-10-17 09:55:59 -05:00
|
|
|
|
|
|
|
fn evil(x: &mut Bool) {
|
|
|
|
let x = x as *mut _ as *mut u32;
|
2022-06-21 13:38:02 -05:00
|
|
|
unsafe {
|
2022-06-21 13:40:02 -05:00
|
|
|
*x = 44; // out-of-bounds enum tag
|
|
|
|
}
|
2018-10-17 09:55:59 -05:00
|
|
|
}
|
|
|
|
|
2022-04-30 13:07:36 -05:00
|
|
|
#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
|
2018-10-17 09:55:59 -05:00
|
|
|
fn main() {
|
|
|
|
let mut x = Bool::True;
|
|
|
|
evil(&mut x);
|
2020-09-20 05:02:04 -05:00
|
|
|
let y = x; // reading this ought to be enough to trigger validation
|
2021-06-15 03:11:49 -05:00
|
|
|
//~^ ERROR type validation failed at .<enum-tag>: encountered 0x0000002c, but expected a valid enum tag
|
2020-09-20 05:02:04 -05:00
|
|
|
println!("{:?}", y); // make sure it is used (and not optimized away)
|
2018-10-17 09:55:59 -05:00
|
|
|
}
|