]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs
Rollup merge of #105254 - cjgillot:issue-105251, r=oli-obk
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / illegal_dealloc1.rs
1 //@error-pattern: /deallocation .* tag does not exist in the borrow stack/
2 use std::alloc::{alloc, dealloc, Layout};
3
4 fn main() {
5     unsafe {
6         let x = alloc(Layout::from_size_align_unchecked(1, 1));
7         let ptr1 = (&mut *x) as *mut u8;
8         let ptr2 = (&mut *ptr1) as *mut u8;
9         // Invalidate ptr2 by writing to ptr1.
10         ptr1.write(0);
11         // Deallocate through ptr2.
12         dealloc(ptr2, Layout::from_size_align_unchecked(1, 1));
13     }
14 }