]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/validity/transmute_through_ptr.rs
Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk
[rust.git] / src / tools / miri / tests / fail / validity / transmute_through_ptr.rs
1 #[repr(u32)]
2 #[derive(Debug)]
3 enum Bool {
4     True,
5 }
6
7 fn evil(x: &mut Bool) {
8     let x = x as *mut _ as *mut u32;
9     unsafe { *x = 44 }; // out-of-bounds enum tag
10 }
11
12 #[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
13 fn main() {
14     let mut x = Bool::True;
15     evil(&mut x);
16     let y = x; // reading this ought to be enough to trigger validation
17     //~^ ERROR: constructing invalid value at .<enum-tag>: encountered 0x0000002c, but expected a valid enum tag
18     println!("{:?}", y); // make sure it is used (and not optimized away)
19 }