rust/tests/ui/borrowck/borrowck-pat-reassign-binding.rs

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

16 lines
421 B
Rust
Raw Normal View History

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