]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/notunpin_dereferenceable_fakeread.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / notunpin_dereferenceable_fakeread.rs
1 //! Reborrowing a `&mut !Unpin` must still act like a (fake) read.
2 use std::marker::PhantomPinned;
3
4 struct NotUnpin(i32, PhantomPinned);
5
6 fn main() {
7     unsafe {
8         let mut x = NotUnpin(0, PhantomPinned);
9         // Mutable borrow of `Unpin` field (with lifetime laundering)
10         let fieldref = &mut *(&mut x.0 as *mut i32);
11         // Mutable reborrow of the entire `x`, which is `!Unpin` but should
12         // still count as a read since we would add `dereferenceable`.
13         let _xref = &mut x;
14         // That read should have invalidated `fieldref`.
15         *fieldref = 0; //~ ERROR: /write access .* tag does not exist in the borrow stack/
16     }
17 }