2017-09-13 05:27:13 -05:00
|
|
|
// Make sure validation can handle many overlapping shared borrows for different parts of a data structure
|
2017-08-07 14:34:33 -05:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
struct Test {
|
|
|
|
a: u32,
|
|
|
|
b: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test1() {
|
|
|
|
let t = &mut Test { a: 0, b: 0 };
|
|
|
|
{
|
|
|
|
let x;
|
|
|
|
{
|
|
|
|
let y = &t.a;
|
|
|
|
x = &t;
|
|
|
|
let _y = *y;
|
|
|
|
}
|
|
|
|
let _x = x.a;
|
|
|
|
}
|
|
|
|
t.b = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test2(r: &mut RefCell<i32>) {
|
|
|
|
let x = &*r; // releasing write lock, first suspension recorded
|
|
|
|
let mut x_ref = x.borrow_mut();
|
2017-09-13 05:27:13 -05:00
|
|
|
let x_inner : &mut i32 = &mut *x_ref; // new inner write lock, with same lifetime as outer lock
|
2018-12-02 04:26:09 -06:00
|
|
|
let _x_inner_shr = &*x_inner; // releasing inner write lock, recording suspension
|
|
|
|
let _y = &*r; // second suspension for the outer write lock
|
|
|
|
let _x_inner_shr2 = &*x_inner; // 2nd suspension for inner write lock
|
2017-08-07 14:34:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
test1();
|
|
|
|
test2(&mut RefCell::new(0));
|
|
|
|
}
|