Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustStacked/Tree BorrowsSingle-choice MCQ

In Miri's Stacked Borrows model, why is the following sequence flagged as undefined behavior even though it compiles and 'works' under normal optimization?

let mut x = 0i32; let r: &i32 = &x; let p: *mut i32 = &mut x as *mut i32; unsafe { *p = 5; } // write through raw ptr let _v = *r; // read through shared ref