|
1 | 1 | //@compile-flags: -Zmiri-tree-borrows
|
2 | 2 |
|
3 | 3 | // 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 |
6 | 6 | // write access errors, but in TB an actual write is needed.
|
| 7 | +// A modified version of each is also available that fails Tree Borrows. |
7 | 8 |
|
8 | 9 | mod fnentry_invalidation {
|
9 | 10 | // Copied directly from fail/stacked_borrows/fnentry_invalidation.rs
|
@@ -73,9 +74,22 @@ mod static_memory_modification {
|
73 | 74 | }
|
74 | 75 | }
|
75 | 76 |
|
| 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 | + |
76 | 89 | fn main() {
|
77 | 90 | fnentry_invalidation::main();
|
78 | 91 | pass_invalid_mut::main();
|
79 | 92 | return_invalid_mut::main();
|
80 | 93 | static_memory_modification::main();
|
| 94 | + interior_mut_reborrow(); |
81 | 95 | }
|
0 commit comments