summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/move-errors.rs
blob: e0fcd6250322dc4b63011c2e7ff85dd1ff62c53a (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
struct A(String);
struct C(D);

fn suggest_remove_deref() {
    let a = &A("".to_string());
    let b = *a;
    //~^ ERROR
}

fn suggest_borrow() {
    let a = [A("".to_string())];
    let b = a[0];
    //~^ ERROR
}

fn suggest_borrow2() {
    let mut a = A("".to_string());
    let r = &&mut a;
    let s = **r;
    //~^ ERROR
}

fn suggest_borrow3() {
    use std::rc::Rc;
    let mut a = A("".to_string());
    let r = Rc::new(a);
    let s = *r;
    //~^ ERROR
}

fn suggest_borrow4() {
    let a = [A("".to_string())][0];
    //~^ ERROR
}

fn suggest_borrow5() {
    let a = &A("".to_string());
    let A(s) = *a;
    //~^ ERROR
}

fn suggest_ref() {
    let c = C(D(String::new()));
    let C(D(s)) = c;
    //~^ ERROR
}

fn suggest_nothing() {
    let a = &A("".to_string());
    let b;
    b = *a;
    //~^ ERROR
}

enum B {
    V(String),
    U(D),
}

struct D(String);

impl Drop for D {
    fn drop(&mut self) {}
}

struct F(String, String);

impl Drop for F {
    fn drop(&mut self) {}
}

fn probably_suggest_borrow() {
    let x = [B::V(String::new())];
    match x[0] {
    //~^ ERROR
        B::U(d) => (),
        B::V(s) => (),
    }
}

fn have_to_suggest_ref() {
    let x = B::V(String::new());
    match x {
    //~^ ERROR
        B::V(s) => drop(s),
        B::U(D(s)) => (),
    };
}

fn two_separate_errors() {
    let x = (D(String::new()), &String::new());
    match x {
    //~^ ERROR
    //~^^ ERROR
        (D(s), &t) => (),
        _ => (),
    }
}

fn have_to_suggest_double_ref() {
    let x = F(String::new(), String::new());
    match x {
    //~^ ERROR
        F(s, mut t) => (),
        _ => (),
    }
}

fn double_binding(x: &Result<String, String>) {
    match *x {
    //~^ ERROR
        Ok(s) | Err(s) => (),
    }
}

fn main() {
}