I encountered in my code a situation where all the immutable references to an object have been dropped, but the borrow checker still complained the object could not be mut borrowed.
I tried to create simpler self-contained demonstration of the issue, but it didn't happen until I made it almost as complex as the real code.
In the gist bellow, I have one while let and a loop, both identical in function, but in the while let the borrow checker complains and provides a wrong suggestion on how to fix, in the loop it compiles just fine.
Is there some hidden semantic that make the code invalid with while let but valid with loop that I am unaware about? Is this some bug or improvement request that is worth reporting somewhere else?
Haven't digged deep yet, but note that your desugaring of while let is incorrect - the real one is (and it gives the same error):
loop {
if let Some((x, mut y)) = c.a.get(&c.b) {
println!("{:#?}, {:#?}", x.v, y.iter.next());
// There should be no more immutable references to c after this drop:
drop(y);
c.inf(2);
} else {
break;
};
}
Here's a much smaller repro, although it doesn't print the nonsensical suggestion (I suspect the suggestion comes from some part in the compiler not considering the desugaring and suggests as if this was actual code, btw).