]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-move-out-of-vec-tail.rs
Rollup merge of #63055 - Mark-Simulacrum:save-analysis-clean-2, r=Xanewok
[rust.git] / src / test / ui / borrowck / borrowck-move-out-of-vec-tail.rs
1 // Test that we do not permit moves from &[] matched by a vec pattern.
2
3 #![feature(slice_patterns)]
4
5 #[derive(Clone, Debug)]
6 struct Foo {
7     string: String
8 }
9
10 pub fn main() {
11     let x = vec![
12         Foo { string: "foo".to_string() },
13         Foo { string: "bar".to_string() },
14         Foo { string: "baz".to_string() }
15     ];
16     let x: &[Foo] = &x;
17     match *x {
18         [_, ref tail @ ..] => {
19             match tail {
20             //~^ ERROR cannot move out of type `[Foo]`
21                 &[Foo { string: a },
22                   Foo { string: b }] => {
23                 }
24                 _ => {
25                     unreachable!();
26                 }
27             }
28             let z = tail[0].clone();
29             println!("{:?}", z);
30         }
31         _ => {
32             unreachable!();
33         }
34     }
35 }