test that creating a 2nd mutable ref from a NonNull invalidates the first

This commit is contained in:
Ralf Jung 2019-04-18 13:20:01 +02:00
parent ae9e9cb47c
commit 7d9dc6e698

View file

@ -0,0 +1,10 @@
use std::ptr::NonNull;
fn main() { unsafe {
let x = &mut 0;
let mut ptr1 = NonNull::from(x);
let mut ptr2 = ptr1.clone();
let raw1 = ptr1.as_mut();
let _raw2 = ptr2.as_mut();
let _val = *raw1; //~ ERROR borrow stack
} }