]> git.lizzy.rs Git - rust.git/blob - tests/fail/stacked_borrows/newtype_retagging.rs
Use the better FnEntry spans in protector errors
[rust.git] / tests / fail / stacked_borrows / newtype_retagging.rs
1 //@compile-flags: -Zmiri-retag-fields
2 //@error-pattern: which is protected
3 struct Newtype<'a>(&'a mut i32);
4
5 fn dealloc_while_running(_n: Newtype<'_>, dealloc: impl FnOnce()) {
6     dealloc();
7 }
8
9 // Make sure that we protect references inside structs.
10 fn main() {
11     let ptr = Box::into_raw(Box::new(0i32));
12     #[rustfmt::skip] // I like my newlines
13     unsafe {
14         dealloc_while_running(
15             Newtype(&mut *ptr),
16             || drop(Box::from_raw(ptr)),
17         )
18     };
19 }