rust/tests/fail/stacked_borrows/track_caller.rs
Ben Kimock 14e72e7ffa Improve information sharing across SB diagnostics
Previous Stacked Borrows diagnostics were missing a lot of information
about the state of the interpreter, and it was difficult to add
additional state because it was threaded through all the intervening
function signatures.

This change factors a lot of the arguments which used to be passed
individually to many stacked borrows functions into a single
`DiagnosticCx`, which is built in `Stacks::for_each`, and since it
wraps a handle to `AllocHistory`, we can now handle more nuanced
things like heterogeneous borrow of `!Freeze` types.
2022-08-18 15:01:03 -04:00

18 lines
641 B
Rust

// 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 };
}