-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #1163 - RalfJung:raw-cast, r=RalfJung
Test raw-ptr-cast without reborrow With rust-lang/rust#64588 landed, we can finally test these things adequately. :)
- Loading branch information
Showing
3 changed files
with
18 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Make sure that creating a raw ptr next to a shared ref works | ||
// but the shared ref still gets invalidated when the raw ptr is used for writing. | ||
|
||
fn main() { unsafe { | ||
use std::mem; | ||
let x = &mut 0; | ||
let y1: &i32 = mem::transmute(&*x); // launder lifetimes | ||
let y2 = x as *mut _; | ||
let _val = *y2; | ||
let _val = *y1; | ||
*y2 += 1; | ||
let _fail = *y1; //~ ERROR borrow stack | ||
} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
[$DIR/stacked-borrows.rs:168] a = "hello world" | ||
[$DIR/stacked-borrows.rs:168] b = [ | ||
0, | ||
1, | ||
2, | ||
4, | ||
] | ||
"hello world" [0, 1, 2, 4] |