diff options
| author | Ralf Jung <post@ralfj.de> | 2024-02-26 10:53:26 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-02-26 10:54:06 +0100 |
| commit | 6c945dd5a053df4d30b5808b5954069b18fc4908 (patch) | |
| tree | 1f68cbaf9774a64ecb328c897e99785e34011f5c | |
| parent | 7cadf0b2da0d83d5d38c8eddb033acf1508942e0 (diff) | |
| download | rust-6c945dd5a053df4d30b5808b5954069b18fc4908.tar.gz rust-6c945dd5a053df4d30b5808b5954069b18fc4908.zip | |
tree borrows: add a test to sb_fails
| -rw-r--r-- | src/tools/miri/tests/pass/tree_borrows/sb_fails.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/tools/miri/tests/pass/tree_borrows/sb_fails.rs b/src/tools/miri/tests/pass/tree_borrows/sb_fails.rs index 5973ef01ead..1bae30bde60 100644 --- a/src/tools/miri/tests/pass/tree_borrows/sb_fails.rs +++ b/src/tools/miri/tests/pass/tree_borrows/sb_fails.rs @@ -1,9 +1,10 @@ //@compile-flags: -Zmiri-tree-borrows // These tests fail Stacked Borrows, but pass Tree Borrows. -// A modified version of each is also available that fails Tree Borrows. -// They all have in common that in SB a mutable reborrow is enough to produce + +// The first four have in common that in SB a mutable reborrow is enough to produce // write access errors, but in TB an actual write is needed. +// A modified version of each is also available that fails Tree Borrows. mod fnentry_invalidation { // Copied directly from fail/stacked_borrows/fnentry_invalidation.rs @@ -73,9 +74,22 @@ mod static_memory_modification { } } +// This one is about direct writes to local variables not being in conflict +// with interior mutable reborrows. +#[allow(unused_assignments)] // spurious warning +fn interior_mut_reborrow() { + use std::cell::UnsafeCell; + + let mut c = UnsafeCell::new(42); + let ptr = c.get(); // first create interior mutable ptr + c = UnsafeCell::new(13); // then write to parent + assert_eq!(unsafe { ptr.read() }, 13); // then read through previous ptr +} + fn main() { fnentry_invalidation::main(); pass_invalid_mut::main(); return_invalid_mut::main(); static_memory_modification::main(); + interior_mut_reborrow(); } |
