]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/track_caller.rs
Rollup merge of #101664 - mejrs:similarity, r=fee1-dead
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / track_caller.rs
1 // This is a copy of illegal_read1.rs, but with #[track_caller] on the test.
2 // This test only checks that our diagnostics do not display the contents of callee.
3
4 #[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
5 fn main() {
6     let mut x = 15;
7     let xraw = &mut x as *mut _;
8     let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still ok...
9     callee(xraw);
10     let _val = *xref; // ...but any use of raw will invalidate our ref.
11     //~^ ERROR: /read access .* tag does not exist in the borrow stack/
12 }
13
14 #[track_caller]
15 fn callee(xraw: *mut i32) {
16     let _val = unsafe { *xraw };
17 }