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
155
156
157
|
#![warn(clippy::match_ref_pats)]
#![allow(dead_code, unused_variables)]
#![allow(
clippy::enum_variant_names,
clippy::equatable_if_let,
clippy::uninlined_format_args,
clippy::empty_loop,
clippy::diverging_sub_expression
)]
fn ref_pats() {
{
let v = &Some(0);
match v {
//~^ match_ref_pats
&Some(v) => println!("{:?}", v),
&None => println!("none"),
}
match v {
// This doesn't trigger; we have a different pattern.
&Some(v) => println!("some"),
other => println!("other"),
}
}
let tup = &(1, 2);
match tup {
&(v, 1) => println!("{}", v),
_ => println!("none"),
}
// Special case: using `&` both in expr and pats.
let w = Some(0);
match &w {
//~^ match_ref_pats
&Some(v) => println!("{:?}", v),
&None => println!("none"),
}
// False positive: only wildcard pattern.
let w = Some(0);
#[allow(clippy::match_single_binding)]
match w {
_ => println!("none"),
}
let a = &Some(0);
if let &None = a {
//~^ redundant_pattern_matching
println!("none");
}
let b = Some(0);
if let &None = &b {
//~^ redundant_pattern_matching
println!("none");
}
}
mod ice_3719 {
macro_rules! foo_variant(
($idx:expr) => (Foo::get($idx).unwrap())
);
enum Foo {
A,
B,
}
impl Foo {
fn get(idx: u8) -> Option<&'static Self> {
match idx {
0 => Some(&Foo::A),
1 => Some(&Foo::B),
_ => None,
}
}
}
fn ice_3719() {
// ICE #3719
match foo_variant!(0) {
&Foo::A => println!("A"),
_ => println!("Wild"),
}
}
}
mod issue_7740 {
macro_rules! foobar_variant(
($idx:expr) => (FooBar::get($idx).unwrap())
);
enum FooBar {
Foo,
Bar,
FooBar,
BarFoo,
}
impl FooBar {
fn get(idx: u8) -> Option<&'static Self> {
match idx {
0 => Some(&FooBar::Foo),
1 => Some(&FooBar::Bar),
2 => Some(&FooBar::FooBar),
3 => Some(&FooBar::BarFoo),
_ => None,
}
}
}
fn issue_7740() {
// Issue #7740
match foobar_variant!(0) {
//~^ match_ref_pats
&FooBar::Foo => println!("Foo"),
&FooBar::Bar => println!("Bar"),
&FooBar::FooBar => println!("FooBar"),
_ => println!("Wild"),
}
// This shouldn't trigger
if let &FooBar::BarFoo = foobar_variant!(3) {
println!("BarFoo");
} else {
println!("Wild");
}
}
}
mod issue15378 {
fn never_in_match() {
match unimplemented!() {
&_ => {},
&&&42 => {
todo!()
},
_ => {},
}
match panic!() {
&_ => {},
&&&42 => {
todo!()
},
_ => {},
}
match loop {} {
&_ => {},
&&&42 => {
todo!()
},
_ => {},
}
}
}
fn main() {}
|