summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/borrowck-move-out-of-vec-tail.rs
blob: 8ece81a3c845e9209a20699ff9664cfc854cbcde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Test that we do not permit moves from &[] matched by a vec pattern.

#[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 {
        [_, ref tail @ ..] => {
            match tail {
            //~^ ERROR cannot move out of type `[Foo]`
                &[Foo { string: a },
                  Foo { string: b }] => {
                }
                _ => {
                    unreachable!();
                }
            }
            let z = tail[0].clone();
            println!("{:?}", z);
        }
        _ => {
            unreachable!();
        }
    }
}