about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/stacked_borrows/track_caller.rs
blob: 3455eb4684ea228f78eadbffecc2ed7e0790c071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// This is a copy of illegal_read1.rs, but with #[track_caller] on the test.
// This test only checks that our diagnostics do not display the contents of callee.

#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
fn main() {
    let mut x = 15;
    let xraw = &mut x as *mut _;
    let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still ok...
    callee(xraw);
    let _val = *xref; // ...but any use of raw will invalidate our ref.
    //~^ ERROR: /read access .* tag does not exist in the borrow stack/
}

#[track_caller]
fn callee(xraw: *mut i32) {
    let _val = unsafe { *xraw };
}