about summary refs log tree commit diff
path: root/tests/ui/or-patterns/binding-typo-2.rs
blob: 275b68a22e22f142356fd65d3e8888c3ab12acd4 (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
// Issue #51976
#![deny(unused_variables)] //~ NOTE: the lint level is defined here
enum Lol {
    Foo,
    Bar,
}
const Bat: () = ();
const Battery: () = ();
struct Bay;

fn foo(x: (Lol, Lol)) {
    use Lol::*;
    match &x {
        (Foo, Bar) | (Ban, Foo) => {}
        //~^ ERROR: variable `Ban` is not bound in all patterns
        //~| HELP: you might have meant to use the similarly named previously used binding `Bar`
        //~| NOTE: pattern doesn't bind `Ban`
        //~| NOTE: variable not in all patterns
        //~| ERROR: variable `Ban` is assigned to, but never used
        //~| NOTE: consider using `_Ban` instead
        //~| HELP: you might have meant to pattern match on the similarly named
        _ => {}
    }
    match &x {
        (Foo, _) | (Ban, Foo) => {}
        //~^ ERROR: variable `Ban` is not bound in all patterns
        //~| HELP: you might have meant to use the similarly named unit variant `Bar`
        //~| NOTE: pattern doesn't bind `Ban`
        //~| NOTE: variable not in all patterns
        //~| ERROR: variable `Ban` is assigned to, but never used
        //~| NOTE: consider using `_Ban` instead
        //~| HELP: you might have meant to pattern match on the similarly named
        _ => {}
    }
    match Some(42) {
        Some(_) => {}
        Non => {}
        //~^ ERROR: unused variable: `Non`
        //~| HELP: if this is intentional, prefix it with an underscore
        //~| HELP: you might have meant to pattern match on the similarly named
    }
    match Some(42) {
        Some(_) => {}
        Non | None => {}
        //~^ ERROR: unused variable: `Non`
        //~| HELP: if this is intentional, prefix it with an underscore
        //~| ERROR: variable `Non` is not bound in all patterns [E0408]
        //~| NOTE: pattern doesn't bind `Non`
        //~| NOTE: variable not in all patterns
        //~| HELP: you might have meant to use the similarly named unit variant `None`
        //~| HELP: you might have meant to pattern match on the similarly named
    }
    match Some(42) {
        Non | Some(_) => {}
        //~^ ERROR: unused variable: `Non`
        //~| HELP: if this is intentional, prefix it with an underscore
        //~| ERROR: variable `Non` is not bound in all patterns [E0408]
        //~| NOTE: pattern doesn't bind `Non`
        //~| NOTE: variable not in all patterns
        //~| HELP: you might have meant to use the similarly named unit variant `None`
        //~| HELP: you might have meant to pattern match on the similarly named
    }
}
fn bar(x: (Lol, Lol)) {
    use Lol::*;
    use ::Bat;
    use ::Bay;
    match &x {
        (Foo, _) | (Ban, Foo) => {}
        //~^ ERROR: variable `Ban` is not bound in all patterns
        //~| HELP: you might have meant to use the similarly named unit variant `Bar`
        //~| HELP: you might have meant to use the similarly named unit struct `Bay`
        //~| HELP: you might have meant to use the similarly named constant `Bat`
        //~| NOTE: pattern doesn't bind `Ban`
        //~| NOTE: variable not in all patterns
        //~| ERROR: variable `Ban` is assigned to, but never used
        //~| NOTE: consider using `_Ban` instead
        //~| HELP: you might have meant to pattern match on the similarly named
        _ => {}
    }
}
fn baz(x: (Lol, Lol)) {
    use Lol::*;
    use Bat;
    match &x {
        (Foo, _) | (Ban, Foo) => {}
        //~^ ERROR: variable `Ban` is not bound in all patterns
        //~| HELP: you might have meant to use the similarly named unit variant `Bar`
        //~| HELP: you might have meant to use the similarly named constant `Bat`
        //~| NOTE: pattern doesn't bind `Ban`
        //~| NOTE: variable not in all patterns
        //~| ERROR: variable `Ban` is assigned to, but never used
        //~| NOTE: consider using `_Ban` instead
        //~| HELP: you might have meant to pattern match on the similarly named
        _ => {}
    }
    match &x {
        (Ban, _) => {}
        //~^ ERROR: unused variable: `Ban`
        //~| HELP: if this is intentional, prefix it with an underscore
        //~| HELP: you might have meant to pattern match on the similarly named
    }
    match Bay {
        Ban => {}
        //~^ ERROR: unused variable: `Ban`
        //~| HELP: if this is intentional, prefix it with an underscore
        //~| HELP: you might have meant to pattern match on the similarly named
    }
    match () {
        Batery => {}
        //~^ ERROR: unused variable: `Batery`
        //~| HELP: if this is intentional, prefix it with an underscore
        //~| HELP: you might have meant to pattern match on the similarly named constant
    }
}

fn main() {
    use Lol::*;
    foo((Foo, Bar));
    bar((Foo, Bar));
    baz((Foo, Bar));
}