]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/invalidate_against_protector3.rs
Rollup merge of #105459 - jyn514:proc-macro-default, r=Mark-Simulacrum
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / invalidate_against_protector3.rs
1 use std::alloc::{alloc, Layout};
2
3 fn inner(x: *mut i32, _y: &i32) {
4     // If `x` and `y` alias, retagging is fine with this... but we really
5     // shouldn't be allowed to write to `x` at all because `y` was assumed to be
6     // immutable for the duration of this call.
7     unsafe { *x = 0 }; //~ ERROR: protect
8 }
9
10 fn main() {
11     unsafe {
12         let ptr = alloc(Layout::for_value(&0i32)) as *mut i32;
13         inner(ptr, &*ptr);
14     };
15 }