]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/newtype_pair_retagging.rs
Rollup merge of #104419 - Ayush1325:test-issue-30490, r=lcnr
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / newtype_pair_retagging.rs
1 //@error-pattern: which is protected
2 struct Newtype<'a>(&'a mut i32, i32);
3
4 fn dealloc_while_running(_n: Newtype<'_>, dealloc: impl FnOnce()) {
5     dealloc();
6 }
7
8 // Make sure that we protect references inside structs that are passed as ScalarPair.
9 fn main() {
10     let ptr = Box::into_raw(Box::new(0i32));
11     #[rustfmt::skip] // I like my newlines
12     unsafe {
13         dealloc_while_running(
14             Newtype(&mut *ptr, 0),
15             || drop(Box::from_raw(ptr)),
16         )
17     };
18 }