add local_addr_of_mut test

This commit is contained in:
Ralf Jung 2023-08-02 18:31:54 +02:00
parent c9512084bd
commit df3b25f386

View File

@ -11,6 +11,7 @@ fn main() {
string_as_mut_ptr(); string_as_mut_ptr();
two_mut_protected_same_alloc(); two_mut_protected_same_alloc();
direct_mut_to_const_raw(); direct_mut_to_const_raw();
local_addr_of_mut();
// Stacked Borrows tests // Stacked Borrows tests
read_does_not_invalidate1(); read_does_not_invalidate1();
@ -31,6 +32,17 @@ fn main() {
write_does_not_invalidate_all_aliases(); write_does_not_invalidate_all_aliases();
} }
#[allow(unused_assignments)]
fn local_addr_of_mut() {
let mut local = 0;
let ptr = ptr::addr_of_mut!(local);
// In SB, `local` and `*ptr` would have different tags, but in TB they have the same tag.
local = 1;
unsafe { *ptr = 2 };
local = 3;
unsafe { *ptr = 4 };
}
// Tree Borrows has no issue with several mutable references existing // Tree Borrows has no issue with several mutable references existing
// at the same time, as long as they are used only immutably. // at the same time, as long as they are used only immutably.
// I.e. multiple Reserved can coexist. // I.e. multiple Reserved can coexist.