Skip to content

Commit df3b25f

Browse files
committed
add local_addr_of_mut test
1 parent c951208 commit df3b25f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111
string_as_mut_ptr();
1212
two_mut_protected_same_alloc();
1313
direct_mut_to_const_raw();
14+
local_addr_of_mut();
1415

1516
// Stacked Borrows tests
1617
read_does_not_invalidate1();
@@ -31,6 +32,17 @@ fn main() {
3132
write_does_not_invalidate_all_aliases();
3233
}
3334

35+
#[allow(unused_assignments)]
36+
fn local_addr_of_mut() {
37+
let mut local = 0;
38+
let ptr = ptr::addr_of_mut!(local);
39+
// In SB, `local` and `*ptr` would have different tags, but in TB they have the same tag.
40+
local = 1;
41+
unsafe { *ptr = 2 };
42+
local = 3;
43+
unsafe { *ptr = 4 };
44+
}
45+
3446
// Tree Borrows has no issue with several mutable references existing
3547
// at the same time, as long as they are used only immutably.
3648
// I.e. multiple Reserved can coexist.

0 commit comments

Comments
 (0)