Skip to content

Instantly share code, notes, and snippets.

@sdleffler
Created May 27, 2017 00:29
Show Gist options
  • Save sdleffler/87abc22f7e5bad01ef8fdfe42d875842 to your computer and use it in GitHub Desktop.
Save sdleffler/87abc22f7e5bad01ef8fdfe42d875842 to your computer and use it in GitHub Desktop.
wtf? borrowck pls
pub fn make_mut<'b>(this: &'b mut RcThunk<'a, T>) -> &'b mut T where T: Clone {
if let Some(thunk) = Rc::get_mut(&mut this.0) {
return &mut **thunk;
}
let new_rc = Rc::new(Thunk::computed((*this.0).clone()));
this.0 = new_rc;
RcThunk::get_mut(this).unwrap()
}
error[E0502]: cannot borrow `this.0` as immutable because it is also borrowed as mutable
--> src/unsync.rs:194:48
|
190 | if let Some(thunk) = Rc::get_mut(&mut this.0) {
| ------ mutable borrow occurs here
...
194 | let new_rc = Rc::new(Thunk::computed((*this.0).clone()));
| ^^^^^^ immutable borrow occurs here
...
197 | }
| - mutable borrow ends here
error[E0506]: cannot assign to `this.0` because it is borrowed
--> src/unsync.rs:195:9
|
190 | if let Some(thunk) = Rc::get_mut(&mut this.0) {
| ------ borrow of `this.0` occurs here
...
195 | this.0 = new_rc;
| ^^^^^^^^^^^^^^^ assignment to borrowed `this.0` occurs here
error[E0499]: cannot borrow `*this` as mutable more than once at a time
--> src/unsync.rs:196:26
|
190 | if let Some(thunk) = Rc::get_mut(&mut this.0) {
| ------ first mutable borrow occurs here
...
196 | RcThunk::get_mut(this).unwrap()
| ^^^^ second mutable borrow occurs here
197 | }
| - first borrow ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment