Closed
Description
miri correctly reports UB for this snippet: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=409c5066eff73741feb30e60f99a77b6
fn main() {
let mut x: u8 = 0u8;
let ptr_a = &mut x as *mut u8;
x = 2;
dbg!(&x);
unsafe { *(&mut *ptr_a) = 1; }
dbg!( unsafe { *ptr_a } );
}
But it fails to do so if we add the following: let _ptr_b = &mut x as *mut u8;
in the middle (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=beec17b4d3e748688ff24e9a263f166c)
fn main() {
let mut x: u8 = 0u8;
let ptr_a = &mut x as *mut u8;
x = 2;
dbg!(&x);
let _ptr_b = &mut x as *mut u8;
unsafe { *(&mut *ptr_a) = 1; }
dbg!( unsafe { *ptr_a } );
}
MemeOverloard#4299(Yandros ꜰʀ-ᴇꜱ) in the rust community discord's #black-magic channel mentioned that using -Zmiri-track-raw-pointers
fixes the issue and makes miri complain about the second snippet
I'm not sure what that flag or if this is expected behaviour without it, so I'm opening this issue in case this is a bug
Metadata
Metadata
Assignees
Labels
No labels