]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/moves-based-on-type-exprs.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / test / compile-fail / moves-based-on-type-exprs.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 // Tests that references to move-by-default values trigger moves when
12 // they occur as part of various kinds of expressions.
13
14 #![feature(managed_boxes)]
15
16 struct Foo<A> { f: A }
17 fn guard(_s: ~str) -> bool {fail!()}
18 fn touch<A>(_a: &A) {}
19
20 fn f10() {
21     let x = "hi".to_owned();
22     let _y = Foo { f:x };
23     touch(&x); //~ ERROR use of moved value: `x`
24 }
25
26 fn f20() {
27     let x = "hi".to_owned();
28     let _y = (x, 3);
29     touch(&x); //~ ERROR use of moved value: `x`
30 }
31
32 fn f21() {
33     let x = vec!(1, 2, 3);
34     let _y = (*x.get(0), 3);
35     touch(&x);
36 }
37
38 fn f30(cond: bool) {
39     let x = "hi".to_owned();
40     let y = "ho".to_owned();
41     let _y = if cond {
42         x
43     } else {
44         y
45     };
46     touch(&x); //~ ERROR use of moved value: `x`
47     touch(&y); //~ ERROR use of moved value: `y`
48 }
49
50 fn f40(cond: bool) {
51     let x = "hi".to_owned();
52     let y = "ho".to_owned();
53     let _y = match cond {
54         true => x,
55         false => y
56     };
57     touch(&x); //~ ERROR use of moved value: `x`
58     touch(&y); //~ ERROR use of moved value: `y`
59 }
60
61 fn f50(cond: bool) {
62     let x = "hi".to_owned();
63     let y = "ho".to_owned();
64     let _y = match cond {
65         _ if guard(x) => 10,
66         true => 10,
67         false => 20,
68     };
69     touch(&x); //~ ERROR use of moved value: `x`
70     touch(&y);
71 }
72
73 fn f70() {
74     let x = "hi".to_owned();
75     let _y = [x];
76     touch(&x); //~ ERROR use of moved value: `x`
77 }
78
79 fn f80() {
80     let x = "hi".to_owned();
81     let _y = vec!(x);
82     touch(&x); //~ ERROR use of moved value: `x`
83 }
84
85 fn f100() {
86     let x = vec!("hi".to_owned());
87     let _y = x.move_iter().next().unwrap();
88     touch(&x); //~ ERROR use of moved value: `x`
89 }
90
91 fn f110() {
92     let x = vec!("hi".to_owned());
93     let _y = [x.move_iter().next().unwrap(), ..1];
94     touch(&x); //~ ERROR use of moved value: `x`
95 }
96
97 fn f120() {
98     let mut x = vec!("hi".to_owned(), "ho".to_owned());
99     x.as_mut_slice().swap(0, 1);
100     touch(x.get(0));
101     touch(x.get(1));
102 }
103
104 fn main() {}