]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-move-error-with-note.rs
Auto merge of #46560 - Yoric:incr, r=michaelwoerister
[rust.git] / src / test / ui / borrowck / borrowck-move-error-with-note.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(box_syntax)]
12
13 enum Foo {
14     Foo1(Box<u32>, Box<u32>),
15     Foo2(Box<u32>),
16     Foo3,
17 }
18
19 fn blah() {
20     let f = &Foo::Foo1(box 1, box 2);
21     match *f {             //~ ERROR cannot move out of
22                            //~| cannot move out
23         Foo::Foo1(num1,
24                   num2) => (),
25         Foo::Foo2(num) => (),
26         Foo::Foo3 => ()
27     }
28 }
29
30 struct S {
31     f: String,
32     g: String
33 }
34 impl Drop for S {
35     fn drop(&mut self) { println!("{}", self.f); }
36 }
37
38 fn move_in_match() {
39     match (S {f: "foo".to_string(), g: "bar".to_string()}) {
40         S {         //~ ERROR cannot move out of type `S`, which implements the `Drop` trait
41         //~| cannot move out of here
42             f: _s,
43             g: _t
44         } => {}
45     }
46 }
47
48 // from issue-8064
49 struct A {
50     a: Box<isize>,
51 }
52
53 fn free<T>(_: T) {}
54
55 fn blah2() {
56     let a = &A { a: box 1 };
57     match a.a {           //~ ERROR cannot move out of
58                           //~| cannot move out
59         n => {
60             free(n)
61         }
62     }
63     free(a)
64 }
65
66 fn main() {}