rustup; add an interesting alias test case
This commit is contained in:
parent
e18c681eea
commit
a81ebd8fe3
2 changed files with 19 additions and 1 deletions
|
|
@ -1 +1 @@
|
|||
15d1f811963649c2f18a88c8e0b39958ec02fd70
|
||||
158f8d034b15e65ba8dc0d066358dd0632bfcd6e
|
||||
|
|
|
|||
18
tests/compile-fail/box-cell-alias.rs
Normal file
18
tests/compile-fail/box-cell-alias.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// compile-flags: -Zmiri-track-raw-pointers
|
||||
|
||||
// Taken from <https://github.com/rust-lang/unsafe-code-guidelines/issues/194#issuecomment-520934222>.
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
fn helper(val: Box<Cell<u8>>, ptr: *const Cell<u8>) -> u8 {
|
||||
val.set(10);
|
||||
unsafe { (*ptr).set(20); } //~ ERROR does not have an appropriate item in the borrow stack
|
||||
val.get()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let val: Box<Cell<u8>> = Box::new(Cell::new(25));
|
||||
let ptr: *const Cell<u8> = &*val;
|
||||
let res = helper(val, ptr);
|
||||
assert_eq!(res, 20);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue