-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.Category: This is a bug.NLL-completeWorking towards the "valid code works" goalWorking towards the "valid code works" goalNLL-poloniusIssues related for using Polonius in the borrow checkerIssues related for using Polonius in the borrow checkerT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
struct Node {
child: [Option<Box<Node>>; 3]
}
fn main() {
let mut root: [Option<Box<Node>>; 3] = Default::default();
let mut tree = &mut root;
for _ in 0..3 {
let opt = &mut tree[0]; // line 9
match opt {
None => {
//break; // ok if uncomment this line of code
// if true { break; } // even error with code like this
}
Some(b) => {
tree = &mut b.as_mut().child;
}
}
}
}
error[E0499]: cannot borrow `tree[_]` as mutable more than once at a time
--> t.rs:9:19
|
9 | let opt = &mut tree[0];
| ^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
however, compile ok if add a break statement in the None block
tema3210
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.Category: This is a bug.NLL-completeWorking towards the "valid code works" goalWorking towards the "valid code works" goalNLL-poloniusIssues related for using Polonius in the borrow checkerIssues related for using Polonius in the borrow checkerT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.