]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/box-cell-alias.rs
:arrow_up: rust-analyzer
[rust.git] / src / tools / miri / tests / fail / box-cell-alias.rs
1 //@compile-flags: -Zmiri-strict-provenance
2
3 // Taken from <https://github.com/rust-lang/unsafe-code-guidelines/issues/194#issuecomment-520934222>.
4
5 use std::cell::Cell;
6
7 fn helper(val: Box<Cell<u8>>, ptr: *const Cell<u8>) -> u8 {
8     val.set(10);
9     unsafe { (*ptr).set(20) }; //~ ERROR: does not exist in the borrow stack
10     val.get()
11 }
12
13 fn main() {
14     let val: Box<Cell<u8>> = Box::new(Cell::new(25));
15     let ptr: *const Cell<u8> = &*val;
16     let res = helper(val, ptr);
17     assert_eq!(res, 20);
18 }