Closed
Description
#![feature(nll)]
use std::ops::*;
#[derive(Copy, Clone)]
struct Au(u32);
impl Add<Au> for Au {
type Output = Au;
fn add(self, other: Au) -> Au {
Au(self.0 + other.0)
}
}
impl AddAssign<Au> for Au {
fn add_assign(&mut self, other: Au) {
*self = Au(self.0 + other.0)
}
}
fn main() {
let mut foo = vec![Au(4), Au(5), Au(6)];
foo[2] += foo[2];
}
(playpen)
fails to compile with the following error:
error[E0502]: cannot borrow `foo` as immutable because it is also borrowed as mutable
--> src/main.rs:22:15
|
22 | foo[2] += foo[2];
| --- ^^^ immutable borrow occurs here
| |
| mutable borrow occurs here
However, it works fine without NLL.