]> git.lizzy.rs Git - rust.git/blob - tests/ui/moves/moves-based-on-type-distribute-copy-over-paren.rs
Move /src/test to /tests
[rust.git] / tests / ui / moves / moves-based-on-type-distribute-copy-over-paren.rs
1 // Tests that references to move-by-default values trigger moves when
2 // they occur as part of various kinds of expressions.
3
4 struct Foo<A> { f: A }
5 fn touch<A>(_a: &A) {}
6
7 fn f00() {
8     let x = "hi".to_string();
9     //~^ NOTE move occurs because `x` has type `String`
10     let _y = Foo { f:x };
11     //~^ NOTE value moved here
12     touch(&x); //~ ERROR borrow of moved value: `x`
13     //~^ NOTE value borrowed here after move
14 }
15
16 fn f05() {
17     let x = "hi".to_string();
18     //~^ NOTE move occurs because `x` has type `String`
19     let _y = Foo { f:(((x))) };
20     //~^ NOTE value moved here
21     touch(&x); //~ ERROR borrow of moved value: `x`
22     //~^ NOTE value borrowed here after move
23 }
24
25 fn f10() {
26     let x = "hi".to_string();
27     let _y = Foo { f:x.clone() };
28     touch(&x);
29 }
30
31 fn f20() {
32     let x = "hi".to_string();
33     let _y = Foo { f:(x).clone() };
34     touch(&x);
35 }
36
37 fn f30() {
38     let x = "hi".to_string();
39     let _y = Foo { f:((x)).clone() };
40     touch(&x);
41 }
42
43 fn f40() {
44     let x = "hi".to_string();
45     let _y = Foo { f:(((((((x)).clone()))))) };
46     touch(&x);
47 }
48
49 fn main() {}