summaryrefslogtreecommitdiffstats
path: root/src/test/ui/did_you_mean/compatible-variants.rs
blob: b1c7dc2a7f67297f2e108551b5f70e135ea7092a (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
enum Hey<A, B> {
    A(A),
    B(B),
}

struct Foo {
    bar: Option<i32>,
}

fn f() {}

fn a() -> Option<()> {
    while false {
        //~^ ERROR mismatched types
        f();
    }
    //~^ HELP try adding an expression
}

fn b() -> Result<(), ()> {
    f()
    //~^ ERROR mismatched types
    //~| HELP try adding an expression
}

fn c() -> Option<()> {
    for _ in [1, 2] {
        //~^ ERROR mismatched types
        f();
    }
    //~^ HELP try adding an expression
}

fn d() -> Option<()> {
    c()?
    //~^ ERROR incompatible types
    //~| HELP try removing this `?`
    //~| HELP try adding an expression
}

fn main() {
    let _: Option<()> = while false {};
    //~^ ERROR mismatched types
    //~| HELP try wrapping
    let _: Option<()> = {
        while false {}
        //~^ ERROR mismatched types
        //~| HELP try adding an expression
    };
    let _: Result<i32, i32> = 1;
    //~^ ERROR mismatched types
    //~| HELP try wrapping
    let _: Option<i32> = 1;
    //~^ ERROR mismatched types
    //~| HELP try wrapping
    let _: Hey<i32, i32> = 1;
    //~^ ERROR mismatched types
    //~| HELP try wrapping
    let _: Hey<i32, bool> = false;
    //~^ ERROR mismatched types
    //~| HELP try wrapping
    let bar = 1i32;
    let _ = Foo { bar };
    //~^ ERROR mismatched types
    //~| HELP try wrapping
}

enum A {
    B { b: B },
}

struct A2(B);

enum B {
    Fst,
    Snd,
}

fn foo() {
    let a: A = B::Fst;
    //~^ ERROR mismatched types
    //~| HELP try wrapping
}

fn bar() {
    let a: A2 = B::Fst;
    //~^ ERROR mismatched types
    //~| HELP try wrapping
}