2014-02-05 16:33:10 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-01-24 19:33:48 -08:00
|
|
|
fn a() {
|
2014-02-13 09:46:46 -08:00
|
|
|
let mut vec = [~1, ~2, ~3];
|
2013-01-24 19:33:48 -08:00
|
|
|
match vec {
|
2014-02-13 09:46:46 -08:00
|
|
|
[~ref _a, _, _] => {
|
2014-02-10 07:44:03 -05:00
|
|
|
vec[0] = ~4; //~ ERROR cannot assign
|
2013-01-24 19:33:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn b() {
|
2014-03-05 14:02:44 -08:00
|
|
|
let mut vec = vec!(~1, ~2, ~3);
|
2014-03-05 15:28:08 -08:00
|
|
|
let vec: &mut [~int] = vec.as_mut_slice();
|
2013-01-24 19:33:48 -08:00
|
|
|
match vec {
|
|
|
|
[.._b] => {
|
2014-02-10 07:44:03 -05:00
|
|
|
vec[0] = ~4; //~ ERROR cannot assign
|
2013-01-24 19:33:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 15:11:20 -04:00
|
|
|
fn c() {
|
2014-03-05 14:02:44 -08:00
|
|
|
let mut vec = vec!(~1, ~2, ~3);
|
2014-03-05 15:28:08 -08:00
|
|
|
let vec: &mut [~int] = vec.as_mut_slice();
|
2013-06-20 15:11:20 -04:00
|
|
|
match vec {
|
|
|
|
[_a, .._b] => {
|
|
|
|
//~^ ERROR cannot move out
|
|
|
|
|
|
|
|
// Note: `_a` is *moved* here, but `b` is borrowing,
|
|
|
|
// hence illegal.
|
|
|
|
//
|
|
|
|
// See comment in middle/borrowck/gather_loans/mod.rs
|
|
|
|
// in the case covering these sorts of vectors.
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2014-02-13 09:46:46 -08:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2013-06-20 15:11:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn d() {
|
2014-03-05 14:02:44 -08:00
|
|
|
let mut vec = vec!(~1, ~2, ~3);
|
2014-03-05 15:28:08 -08:00
|
|
|
let vec: &mut [~int] = vec.as_mut_slice();
|
2013-06-20 15:11:20 -04:00
|
|
|
match vec {
|
|
|
|
[.._a, _b] => {
|
|
|
|
//~^ ERROR cannot move out
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2014-02-13 09:46:46 -08:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2013-06-20 15:11:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn e() {
|
2014-03-05 14:02:44 -08:00
|
|
|
let mut vec = vec!(~1, ~2, ~3);
|
2014-03-05 15:28:08 -08:00
|
|
|
let vec: &mut [~int] = vec.as_mut_slice();
|
2013-06-20 15:11:20 -04:00
|
|
|
match vec {
|
2014-02-13 09:46:46 -08:00
|
|
|
[_a, _b, _c] => {} //~ ERROR cannot move out
|
|
|
|
//~^ ERROR cannot move out
|
|
|
|
//~^^ ERROR cannot move out
|
2013-06-20 15:11:20 -04:00
|
|
|
_ => {}
|
|
|
|
}
|
2014-02-13 09:46:46 -08:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2013-06-20 15:11:20 -04:00
|
|
|
}
|
|
|
|
|
2013-01-24 19:33:48 -08:00
|
|
|
fn main() {}
|