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