]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-move-out-of-vec-tail.rs
Rollup merge of #59880 - solson:transmute-float, r=alexcrichton
[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                 &[Foo { string: a },
21                 //~^ ERROR cannot move out of type `[Foo]`
22                 //~| cannot move out
23                 //~| to prevent move
24                   Foo { string: b }] => {
25                 }
26                 _ => {
27                     unreachable!();
28                 }
29             }
30             let z = tail[0].clone();
31             println!("{:?}", z);
32         }
33         _ => {
34             unreachable!();
35         }
36     }
37 }