rust/src/test/compile-fail/borrowck-pat-reassign-binding.rs

14 lines
431 B
Rust
Raw Normal View History

// xfail-pretty -- comments are infaithfully preserved
fn main() {
2012-08-20 12:23:37 -07:00
let mut x: Option<int> = None;
2012-08-06 12:34:08 -07:00
match x { //~ NOTE loan of mutable local variable granted here
2012-08-20 12:23:37 -07:00
None => {}
Some(ref i) => {
// Not ok: i is an outstanding ptr into x.
2012-08-20 12:23:37 -07:00
x = Some(*i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
}
}
copy x; // just to prevent liveness warnings
}