rust/src/test/ui/borrowck/borrowck-pat-reassign-binding.rs

20 lines
534 B
Rust
Raw Normal View History

// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
fn main() {
let mut x: Option<isize> = None;
2013-03-15 14:24:24 -05:00
match x {
None => {
// Note: on this branch, no borrow has occurred.
x = Some(0);
}
2012-08-20 14:23:37 -05:00
Some(ref i) => {
2013-03-15 14:24:24 -05:00
// But on this branch, `i` is an outstanding borrow
x = Some(*i+1); //[ast]~ ERROR cannot assign to `x`
//[mir]~^ ERROR cannot assign to `x` because it is borrowed
drop(i);
}
}
2013-07-02 14:47:32 -05:00
x.clone(); // just to prevent liveness warnings
}