Skip to content

Commit f38d411

Browse files
committed
Auto merge of #3327 - RalfJung:tree-interior_mut_reborrow, r=RalfJung
tree borrows: add a test to sb_fails This is something that happens in the wild (rust-lang/rust#121626), so TB accepting this is good. Let's make sure we notice if this ever changes.
2 parents 456c69e + d9968fa commit f38d411

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/pass/tree_borrows/sb_fails.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//@compile-flags: -Zmiri-tree-borrows
22

33
// These tests fail Stacked Borrows, but pass Tree Borrows.
4-
// A modified version of each is also available that fails Tree Borrows.
5-
// They all have in common that in SB a mutable reborrow is enough to produce
4+
5+
// The first four have in common that in SB a mutable reborrow is enough to produce
66
// write access errors, but in TB an actual write is needed.
7+
// A modified version of each is also available that fails Tree Borrows.
78

89
mod fnentry_invalidation {
910
// Copied directly from fail/stacked_borrows/fnentry_invalidation.rs
@@ -73,9 +74,22 @@ mod static_memory_modification {
7374
}
7475
}
7576

77+
// This one is about direct writes to local variables not being in conflict
78+
// with interior mutable reborrows.
79+
#[allow(unused_assignments)] // spurious warning
80+
fn interior_mut_reborrow() {
81+
use std::cell::UnsafeCell;
82+
83+
let mut c = UnsafeCell::new(42);
84+
let ptr = c.get(); // first create interior mutable ptr
85+
c = UnsafeCell::new(13); // then write to parent
86+
assert_eq!(unsafe { ptr.read() }, 13); // then read through previous ptr
87+
}
88+
7689
fn main() {
7790
fnentry_invalidation::main();
7891
pass_invalid_mut::main();
7992
return_invalid_mut::main();
8093
static_memory_modification::main();
94+
interior_mut_reborrow();
8195
}

0 commit comments

Comments
 (0)