I tried this code:
#[inline(never)]
fn test(x: &i32) {
let addr = (x as *const i32).wrapping_sub(1).addr();
let p: *mut i32 = std::ptr::with_exposed_provenance_mut(addr);
unsafe { *p += 1 };
}
fn main() {
let mut arr = [0, 0];
let [a, b] = arr.get_disjoint_mut([0, 1]).unwrap();
(a as *mut i32).expose_provenance();
test(&b);
dbg!(arr);
}
I expected to see this happen: I'd expect to see [1, 0] printed.
Instead, this happened: in debug mode [1, 0] gets printed, but in release mode [0, 0] gets printed.
Occurs on 1.95 stable and latest nightly.
Found by @ruriww.
I tried this code:
I expected to see this happen: I'd expect to see
[1, 0]printed.Instead, this happened: in debug mode
[1, 0]gets printed, but in release mode[0, 0]gets printed.Occurs on 1.95 stable and latest nightly.
Found by @ruriww.