Open
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