test that we support partial invalidation of mutable references

This commit is contained in:
Ralf Jung 2018-11-21 16:08:46 +01:00
parent a6401e7d1d
commit 04794c4c2a

View File

@ -7,6 +7,7 @@ fn main() {
mut_shr_raw();
mut_raw_then_mut_shr();
mut_raw_mut();
partially_invalidate_mut();
}
// Deref a raw ptr to access a field of a large struct, where the field
@ -97,3 +98,12 @@ fn mut_raw_mut() {
}
assert_eq!(x, 4);
}
fn partially_invalidate_mut() {
let data = &mut (0u8, 0u8);
let reborrow = &mut *data as *mut (u8, u8);
let shard = unsafe { &mut (*reborrow).0 };
data.1 += 1; // the deref overlaps with `shard`, but that is okay; the access does not overlap.
*shard += 1; // so we can still use `shard`.
assert_eq!(*data, (1, 1));
}