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.
|
|
|
|
|
|
2014-09-06 13:52:07 -07:00
|
|
|
#![feature(advanced_slice_patterns)]
|
2015-02-10 22:52:00 +01:00
|
|
|
#![feature(box_patterns)]
|
2015-01-07 22:35:56 +01:00
|
|
|
#![feature(box_syntax)]
|
2015-03-26 18:34:27 -07:00
|
|
|
#![feature(slice_patterns)]
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2013-01-24 19:33:48 -08:00
|
|
|
fn a() {
|
2015-01-31 17:23:42 +01:00
|
|
|
let mut vec = [box 1, box 2, box 3];
|
2013-01-24 19:33:48 -08:00
|
|
|
match vec {
|
2014-05-05 18:56:44 -07:00
|
|
|
[box ref _a, _, _] => {
|
2016-03-14 23:36:43 -04:00
|
|
|
//~^ borrow of `vec[..]` occurs here
|
2014-05-05 18:56:44 -07:00
|
|
|
vec[0] = box 4; //~ ERROR cannot assign
|
2016-05-16 18:40:50 -04:00
|
|
|
//~^ assignment to borrowed `vec[..]` occurs here
|
2013-01-24 19:33:48 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn b() {
|
2016-10-29 22:54:04 +01:00
|
|
|
let mut vec = vec![box 1, box 2, box 3];
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-01-24 19:33:48 -08:00
|
|
|
match vec {
|
2016-03-11 12:54:59 +02:00
|
|
|
&mut [ref _b..] => {
|
2016-03-14 23:36:43 -04:00
|
|
|
//~^ borrow of `vec[..]` occurs here
|
2014-05-05 18:56:44 -07:00
|
|
|
vec[0] = box 4; //~ ERROR cannot assign
|
2016-05-16 18:40:50 -04:00
|
|
|
//~^ assignment to borrowed `vec[..]` occurs here
|
2013-01-24 19:33:48 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 15:11:20 -04:00
|
|
|
fn c() {
|
2016-10-29 22:54:04 +01:00
|
|
|
let mut vec = vec![box 1, box 2, box 3];
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-06-20 15:11:20 -04:00
|
|
|
match vec {
|
2016-09-16 16:02:43 +03:00
|
|
|
&mut [_a, //~ ERROR cannot move out
|
2016-03-11 12:54:59 +02:00
|
|
|
//~| cannot move out
|
|
|
|
|
//~| to prevent move
|
|
|
|
|
..
|
|
|
|
|
] => {
|
2013-06-20 15:11:20 -04:00
|
|
|
// 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
|
2016-05-16 18:40:50 -04:00
|
|
|
//~| cannot move out of here
|
2013-06-20 15:11:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn d() {
|
2016-10-29 22:54:04 +01:00
|
|
|
let mut vec = vec![box 1, box 2, box 3];
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-06-20 15:11:20 -04:00
|
|
|
match vec {
|
2016-03-11 12:54:59 +02:00
|
|
|
&mut [ //~ ERROR cannot move out
|
2016-05-16 18:40:50 -04:00
|
|
|
//~^ cannot move out
|
|
|
|
|
_b] => {} //~ NOTE to prevent move
|
2013-06-20 15:11:20 -04:00
|
|
|
_ => {}
|
|
|
|
|
}
|
2014-02-13 09:46:46 -08:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2016-05-16 18:40:50 -04:00
|
|
|
//~| cannot move out of here
|
2013-06-20 15:11:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn e() {
|
2016-10-29 22:54:04 +01:00
|
|
|
let mut vec = vec![box 1, box 2, box 3];
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-06-20 15:11:20 -04:00
|
|
|
match vec {
|
2016-03-11 12:54:59 +02:00
|
|
|
&mut [_a, _b, _c] => {} //~ ERROR cannot move out
|
2016-05-16 18:40:50 -04:00
|
|
|
//~| cannot move out
|
|
|
|
|
//~| NOTE to prevent move
|
2016-05-12 16:39:09 -07:00
|
|
|
//~| NOTE and here
|
|
|
|
|
//~| NOTE and here
|
2013-06-20 15:11:20 -04:00
|
|
|
_ => {}
|
|
|
|
|
}
|
2014-02-13 09:46:46 -08:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2016-05-16 18:40:50 -04:00
|
|
|
//~| cannot move out of here
|
2013-06-20 15:11:20 -04:00
|
|
|
}
|
|
|
|
|
|
2013-01-24 19:33:48 -08:00
|
|
|
fn main() {}
|