rust/tests/ui/borrowck/borrowck-move-out-of-vec-tail.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
780 B
Rust
Raw Normal View History

// Test that we do not permit moves from &[] matched by a vec pattern.
2015-01-28 07:34:18 -06:00
#[derive(Clone, Debug)]
struct Foo {
string: String
}
pub fn main() {
let x = vec![
Foo { string: "foo".to_string() },
Foo { string: "bar".to_string() },
Foo { string: "baz".to_string() }
];
let x: &[Foo] = &x;
match *x {
2019-07-07 18:47:46 -05:00
[_, ref tail @ ..] => {
match tail {
//~^ ERROR cannot move out of type `[Foo]`
&[Foo { string: a },
Foo { string: b }] => {
}
_ => {
unreachable!();
}
}
2013-07-02 14:47:32 -05:00
let z = tail[0].clone();
println!("{:?}", z);
}
_ => {
unreachable!();
}
}
}