2013-05-22 10:54:35 +00:00
|
|
|
// Test that we do not permit moves from &[] matched by a vec pattern.
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2013-05-22 10:54:35 +00:00
|
|
|
struct Foo {
|
2014-05-22 23:57:53 +00:00
|
|
|
string: String
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2016-10-29 21:54:04 +00:00
|
|
|
let x = vec![
|
2014-05-25 10:17:19 +00:00
|
|
|
Foo { string: "foo".to_string() },
|
|
|
|
Foo { string: "bar".to_string() },
|
|
|
|
Foo { string: "baz".to_string() }
|
2016-10-29 21:54:04 +00:00
|
|
|
];
|
2015-02-02 02:53:25 +00:00
|
|
|
let x: &[Foo] = &x;
|
2016-03-11 10:54:59 +00:00
|
|
|
match *x {
|
2019-07-07 23:47:46 +00:00
|
|
|
[_, ref tail @ ..] => {
|
2013-05-22 10:54:35 +00:00
|
|
|
match tail {
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR cannot move out of type `[Foo]`
|
2016-03-11 10:54:59 +00:00
|
|
|
&[Foo { string: a },
|
|
|
|
Foo { string: b }] => {
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
_ => {
|
2013-09-19 05:04:03 +00:00
|
|
|
unreachable!();
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-02 19:47:32 +00:00
|
|
|
let z = tail[0].clone();
|
2014-12-20 08:09:35 +00:00
|
|
|
println!("{:?}", z);
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
_ => {
|
2013-09-19 05:04:03 +00:00
|
|
|
unreachable!();
|
2013-05-22 10:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|