]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.rs
Auto merge of #105085 - oli-obk:stop_promoting_all_the_things, r=RalfJung
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / drop_in_place_protector.rs
1 //! Test that drop_in_place retags the entire place,
2 //! invalidating all aliases to it.
3
4 // A zero-sized drop type -- the retagging of `fn drop` itself won't
5 // do anything (since it is zero-sized); we are entirely relying on the retagging
6 // in `drop_in_place` here.
7 #[repr(transparent)]
8 struct HasDrop;
9 impl Drop for HasDrop {
10     fn drop(&mut self) {
11         unsafe {
12             let _val = *P;
13             //~^ ERROR: /not granting access .* because that would remove .* which is strongly protected/
14         }
15     }
16 }
17
18 static mut P: *mut u8 = core::ptr::null_mut();
19
20 fn main() {
21     unsafe {
22         let mut x = (HasDrop, 0u8);
23         let x = core::ptr::addr_of_mut!(x);
24         P = x.cast();
25         core::ptr::drop_in_place(x);
26     }
27 }