demo_mut_advanced_unique(mut our: Box<i32>) -> i321fn demo_mut_advanced_unique(mut our: Box<i32>) -> i32 { 2 unknown_code_1(&*our); 3 4 // This "re-asserts" uniqueness of the reference: After writing, we know 5 // our tag is at the top of the stack. 6 *our = 5; 7 8 unknown_code_2(); 9 10 // We know this will return 5 11 *our //~ ERROR borrow stack 12 } 13 14 // Now comes the evil context 15 use std::ptr; 16 17 static mut LEAK: *mut i32 = ptr::null_mut(); 18 unknown_code_1(x: &i32)19fn unknown_code_1(x: &i32) { unsafe { 20 LEAK = x as *const _ as *mut _; 21 } } 22 unknown_code_2()23fn unknown_code_2() { unsafe { 24 *LEAK = 7; 25 } } 26 main()27fn main() { 28 demo_mut_advanced_unique(Box::new(0)); 29 } 30