]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-move-out-of-vec-tail.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / 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 #[derive(Clone, Debug)]
4 struct Foo {
5     string: String
6 }
7
8 pub fn main() {
9     let x = vec![
10         Foo { string: "foo".to_string() },
11         Foo { string: "bar".to_string() },
12         Foo { string: "baz".to_string() }
13     ];
14     let x: &[Foo] = &x;
15     match *x {
16         [_, ref tail @ ..] => {
17             match tail {
18             //~^ ERROR cannot move out of type `[Foo]`
19                 &[Foo { string: a },
20                   Foo { string: b }] => {
21                 }
22                 _ => {
23                     unreachable!();
24                 }
25             }
26             let z = tail[0].clone();
27             println!("{:?}", z);
28         }
29         _ => {
30             unreachable!();
31         }
32     }
33 }