We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 17d0851 + 6eb153a commit e26ecc4Copy full SHA for e26ecc4
tests/run-pass/stacked-borrows.rs
@@ -7,6 +7,7 @@ fn main() {
7
mut_shr_raw();
8
mut_raw_then_mut_shr();
9
mut_raw_mut();
10
+ partially_invalidate_mut();
11
}
12
13
// Deref a raw ptr to access a field of a large struct, where the field
@@ -97,3 +98,12 @@ fn mut_raw_mut() {
97
98
99
assert_eq!(x, 4);
100
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