-
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.
more tests -- also one showing why we are not done yet
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
tests/compile-fail/stacked_borrows/shared_rw_borrows_are_weak1.rs
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,14 @@ | ||
// We want to test that granting a SharedReadWrite will be added | ||
// *below* an already granted Unique -- so writing to | ||
// the SharedReadWrite will invalidate the Unique. | ||
|
||
use std::mem; | ||
use std::cell::Cell; | ||
|
||
fn main() { unsafe { | ||
let x = &mut Cell::new(0); | ||
let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime | ||
let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite | ||
shr_rw.set(1); | ||
y.get_mut(); //~ ERROR borrow stack | ||
} } |
14 changes: 14 additions & 0 deletions
14
tests/compile-fail/stacked_borrows/shared_rw_borrows_are_weak2.rs
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,14 @@ | ||
// We want to test that granting a SharedReadWrite will be added | ||
// *below* an already granted SharedReadWrite -- so writing to | ||
// the SharedReadWrite will invalidate the SharedReadWrite. | ||
|
||
use std::mem; | ||
use std::cell::RefCell; | ||
|
||
fn main() { unsafe { | ||
let x = &mut RefCell::new(0); | ||
let y: &i32 = mem::transmute(&*x.borrow()); // launder lifetime | ||
let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite | ||
shr_rw.replace(1); | ||
let _val = *y; //~ 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