rust/tests/ui/augmented-assignments.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
624 B
Rust
Raw Normal View History

2015-09-11 08:16:57 +08:00
use std::ops::AddAssign;
#[derive(Clone)]
2015-09-11 08:16:57 +08:00
struct Int(i32);
impl AddAssign for Int {
fn add_assign(&mut self, _: Int) {
unimplemented!()
}
}
fn main() {
2023-01-15 11:06:44 +08:00
let mut x = Int(1); //~ NOTE binding `x` declared here
x
//~^ NOTE borrow of `x` occurs here
2015-09-11 08:16:57 +08:00
+=
x;
//~^ ERROR cannot move out of `x` because it is borrowed
//~| move out of `x` occurs here
2015-09-11 08:16:57 +08:00
let y = Int(2);
//~^ HELP consider changing this to be mutable
2023-01-01 16:06:31 +08:00
//~| SUGGESTION mut
y //~ ERROR cannot borrow `y` as mutable, as it is not declared as mutable
//~| cannot borrow as mutable
2015-09-11 08:16:57 +08:00
+=
Int(1);
}