Open
Description
I don't know why this happens but rovar and XMPPwocky on IRC believed it to be a compiler bug.
struct A {
a: i32
}
impl A {
fn one(&mut self) -> &i32{
self.a = 10;
&self.a
}
fn two(&mut self) -> &i32 {
loop {
let k = self.one();
if *k > 10i32 {
return k;
}
}
}
}
...gives the following error...
<anon>:12:21: 12:25 error: cannot borrow `*self` as mutable more than once at a time
<anon>:12 let k = self.one();
^~~~
<anon>:12:21: 12:25 note: previous borrow of `*self` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*self` until the borrow ends
<anon>:12 let k = self.one();
^~~~
<anon>:17:6: 17:6 note: previous borrow ends here
<anon>:10 fn two(&mut self) -> &i32 {
...
<anon>:17 }
^
error: aborting due to previous error
playpen: application terminated with error code 101
Interestingly, if the second method is changed to...
fn two(&mut self) -> &i32 {
loop {
let k = self.one();
return k;
}
}
This will compile fine.
playpen: http://is.gd/mTkfw5