summaryrefslogtreecommitdiffstats
path: root/tests/ui/typeck/explain_clone_autoref.rs
blob: 88aaac469b21da84f75c77815835583cc16cb76c (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
struct NotClone;

fn main() {
    clone_thing(&NotClone);
}

fn clone_thing(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    nc.clone()
    //~^ ERROR mismatched type
    //~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing2(nc: &NotClone) -> NotClone {
    let nc: NotClone = nc.clone();
    //~^ ERROR mismatched type
    //~| NOTE expected due to this
    //~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    //~| NOTE expected `NotClone`, found `&NotClone`
    nc
}

fn clone_thing3(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let nc = nc.clone();
    //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    nc
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing4(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let nc = nc.clone();
    //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    let nc2 = nc;
    nc2
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

impl NotClone {
    fn other_fn(&self) {}
    fn get_ref_notclone(&self) -> &Self {
        self
    }
}

fn clone_thing5(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let nc = nc.clone();
    //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    let nc2 = nc;
    nc2.other_fn();
    let nc3 = nc2;
    nc3
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing6(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let (ret, _) = (nc.clone(), 1);
    //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    let _ = nc.clone();
    ret
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing7(nc: Vec<&NotClone>) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let ret = nc[0].clone();
    //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    ret
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing8(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let ret = {
        let a = nc.clone();
        //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
        a
    };
    ret
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing9(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let cl = || nc.clone();
    //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    let ret = cl();
    ret
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing10(nc: &NotClone) -> (NotClone, NotClone) {
    let (a, b) = {
        let a = nc.clone();
        //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
        (a, nc.clone())
        //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
    };
    (a, b)
    //~^ ERROR mismatched type
    //~| ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
    //~| NOTE expected `NotClone`, found `&NotClone`
}

fn clone_thing11(nc: &NotClone) -> NotClone {
    //~^ NOTE expected `NotClone` because of return type
    let a = {
        let nothing = nc.clone();
        let a = nc.clone();
        //~^ NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
        let nothing = nc.clone();
        a
    };
    a
    //~^ ERROR mismatched type
    //~| NOTE expected `NotClone`, found `&NotClone`
}