rust/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs

33 lines
780 B
Rust
Raw Normal View History

// Test that we do not permit moves from &[] matched by a vec pattern.
2013-07-02 14:47:32 -05:00
#[deriving(Clone)]
struct Foo {
string: ~str
}
pub fn main() {
let x = ~[
Foo { string: ~"foo" },
Foo { string: ~"bar" },
Foo { string: ~"baz" }
];
match x {
[_, ..tail] => {
match tail {
[Foo { string: a }, Foo { string: b }] => {
//~^ ERROR cannot move out of dereference of & pointer
//~^^ ERROR cannot move out of dereference of & pointer
}
_ => {
unreachable!();
}
}
2013-07-02 14:47:32 -05:00
let z = tail[0].clone();
2013-09-29 22:06:21 -05:00
info2!("{:?}", z);
}
_ => {
unreachable!();
}
}
}