-
Notifications
You must be signed in to change notification settings - Fork 13.3k
NLL reports "borrow used here in later iteration of loop" in cases outside of loop #53773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you comment out |
@pnkfelix It seems that would be the relevant issue. I was pointing out what happens when removing the line as it hints at where the problem might be introduced in rustc. |
I believe that the change I suggested in #54015 would also fix this. |
I'm sort of tempted to close one or the other as a duplicate, in fact. |
Adding to RC 2 milestone as a "nice to have", though I think we should merge with #54015 |
This is fixed, presumably by PR #54343 |
I spoke too soon. The current output, according to play, is:
so, we still have the "in later iteration of loop" in the diagnostic. |
Removing from the Rust 2018 Release milestone. |
Created a topic for this on zulip (link) and assigned @spastorino |
So the problem here is that the CFG is very similar to that of: let mut members: Vec<&mut ArchiveChild<'_>> = vec![];
let archive_iter = archive.iter();
loop { match archive_iter.next() {
Some(child) => {
members.push(child.raw);
}
None => {
members.len();
return;
}
}} In which case the error message would be correct. One way to solve this would be to add a |
This commit fixes the logic of detecting when a use happen in a later iteration of where a borrow was defined Fixes rust-lang#53773
NLL triage. P-medium. |
…=pnkfelix Erroneous loop diagnostic in nll Closes #53773 r? @nikomatsakis
Spawned off of #53220 (comment)
In this code (play), we report "borrow used here in later iteration of loop" for the
members.len()
call that is not within the loop.(I assume this is due to some bug in how we are attempting to reverse-engineer the existence of a loop by analyzing the basic-block control-flow of MIR alone.)
The text was updated successfully, but these errors were encountered: