Skip to content

Commit 3e74daa

Browse files
committed
Auto merge of #1659 - RalfJung:rustup, r=RalfJung
rustup; add an interesting alias test case
2 parents e18c681 + a81ebd8 commit 3e74daa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15d1f811963649c2f18a88c8e0b39958ec02fd70
1+
158f8d034b15e65ba8dc0d066358dd0632bfcd6e

tests/compile-fail/box-cell-alias.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Zmiri-track-raw-pointers
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 have an appropriate item 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+
}

0 commit comments

Comments
 (0)