summaryrefslogtreecommitdiffstats
path: root/tests/ui/moves/moves-based-on-type-distribute-copy-over-paren.rs
blob: d256e18b6ca973cbaeae98ff165a663ae0a4b254 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Tests that references to move-by-default values trigger moves when
// they occur as part of various kinds of expressions.

struct Foo<A> { f: A }
fn touch<A>(_a: &A) {}

fn f00() {
    let x = "hi".to_string();
    //~^ NOTE move occurs because `x` has type `String`
    let _y = Foo { f:x };
    //~^ NOTE value moved here
    touch(&x); //~ ERROR borrow of moved value: `x`
    //~^ NOTE value borrowed here after move
}

fn f05() {
    let x = "hi".to_string();
    //~^ NOTE move occurs because `x` has type `String`
    let _y = Foo { f:(((x))) };
    //~^ NOTE value moved here
    touch(&x); //~ ERROR borrow of moved value: `x`
    //~^ NOTE value borrowed here after move
}

fn f10() {
    let x = "hi".to_string();
    let _y = Foo { f:x.clone() };
    touch(&x);
}

fn f20() {
    let x = "hi".to_string();
    let _y = Foo { f:(x).clone() };
    touch(&x);
}

fn f30() {
    let x = "hi".to_string();
    let _y = Foo { f:((x)).clone() };
    touch(&x);
}

fn f40() {
    let x = "hi".to_string();
    let _y = Foo { f:(((((((x)).clone()))))) };
    touch(&x);
}

fn main() {}