-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to fix cyclic re-borrow issue
The fix for the issue described in #28 (reborrow_dependent_cyclic.rs) allows compiling leak_dependent.rs which should not be possible. This is a first attempt and incomplete as seen by the stubbed out impls for with_dependent and with_dependent_mut. DO NOT MERGE
- Loading branch information
1 parent
f94e898
commit 090eac6
Showing
4 changed files
with
58 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::cell::RefCell; | ||
|
||
use self_cell::self_cell; | ||
|
||
struct Bar<'a>(RefCell<(Option<&'a Bar<'a>>, String)>); | ||
|
||
self_cell! { | ||
struct Foo { | ||
owner: (), | ||
|
||
#[not_covariant] | ||
dependent: Bar, | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut x = Foo::new((), |_| Bar(RefCell::new((None, "Hello".to_owned())))); | ||
|
||
x.with_dependent(|_, dep| { | ||
dep.0.borrow_mut().0 = Some(dep); | ||
}); | ||
|
||
x.with_dependent_mut(|_, dep| { | ||
let r1 = dep.0.get_mut(); | ||
let string_ref_1 = &mut r1.1; | ||
let mut r2 = r1.0.unwrap().0.borrow_mut(); | ||
let string_ref_2 = &mut r2.1; | ||
|
||
let s = &string_ref_1[..]; | ||
string_ref_2.clear(); | ||
string_ref_2.shrink_to_fit(); | ||
println!("{}", s); // prints garbage | ||
}); | ||
} |
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