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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#![warn(clippy::match_wildcard_for_single_variants)]
#![allow(dead_code)]
enum Foo {
A,
B,
C,
}
enum Color {
Red,
Green,
Blue,
Rgb(u8, u8, u8),
}
impl Color {
fn f(self) {
match self {
Self::Red => (),
Self::Green => (),
Self::Blue => (),
_ => (),
};
}
}
fn main() {
let f = Foo::A;
match f {
Foo::A => {},
Foo::B => {},
_ => {},
}
let color = Color::Red;
// check exhaustive bindings
match color {
Color::Red => {},
Color::Green => {},
Color::Rgb(_r, _g, _b) => {},
_ => {},
}
// check exhaustive wild
match color {
Color::Red => {},
Color::Green => {},
Color::Rgb(..) => {},
_ => {},
}
match color {
Color::Red => {},
Color::Green => {},
Color::Rgb(_, _, _) => {},
_ => {},
}
// shouldn't lint as there is one missing variant
// and one that isn't exhaustively covered
match color {
Color::Red => {},
Color::Green => {},
Color::Rgb(255, _, _) => {},
_ => {},
}
// References shouldn't change anything
match &color {
&Color::Red => (),
Color::Green => (),
&Color::Rgb(..) => (),
&_ => (),
}
use self::Color as C;
match color {
C::Red => (),
C::Green => (),
C::Rgb(..) => (),
_ => (),
}
match color {
C::Red => (),
Color::Green => (),
Color::Rgb(..) => (),
_ => (),
}
match Some(0) {
Some(0) => 0,
Some(_) => 1,
_ => 2,
};
#[non_exhaustive]
enum Bar {
A,
B,
C,
}
match Bar::A {
Bar::A => (),
Bar::B => (),
_ => (),
};
//#6984
{
#![allow(clippy::manual_non_exhaustive)]
pub enum Enum {
A,
B,
C,
#[doc(hidden)]
__Private,
}
match Enum::A {
Enum::A => (),
Enum::B => (),
Enum::C => (),
_ => (),
}
match Enum::A {
Enum::A => (),
Enum::B => (),
_ => (),
}
}
}
mod issue9993 {
enum Foo {
A(bool),
B,
}
fn test() {
let _ = match Foo::A(true) {
_ if false => 0,
Foo::A(true) => 1,
Foo::A(false) => 2,
Foo::B => 3,
};
let _ = match Foo::B {
_ if false => 0,
Foo::A(_) => 1,
_ => 2,
};
}
}
|