Skip to content

Commit e26ecc4

Browse files
authored
Merge pull request #540 from RalfJung/partially-invalidate-mut
test that we support partial invalidation of mutable references
2 parents 17d0851 + 6eb153a commit e26ecc4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/run-pass/stacked-borrows.rs

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn main() {
77
mut_shr_raw();
88
mut_raw_then_mut_shr();
99
mut_raw_mut();
10+
partially_invalidate_mut();
1011
}
1112

1213
// Deref a raw ptr to access a field of a large struct, where the field
@@ -97,3 +98,12 @@ fn mut_raw_mut() {
9798
}
9899
assert_eq!(x, 4);
99100
}
101+
102+
fn partially_invalidate_mut() {
103+
let data = &mut (0u8, 0u8);
104+
let reborrow = &mut *data as *mut (u8, u8);
105+
let shard = unsafe { &mut (*reborrow).0 };
106+
data.1 += 1; // the deref overlaps with `shard`, but that is okay; the access does not overlap.
107+
*shard += 1; // so we can still use `shard`.
108+
assert_eq!(*data, (1, 1));
109+
}

0 commit comments

Comments
 (0)