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
|
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![feature(if_let_guard)]
#![allow(clippy::no_effect, unused)]
#![warn(clippy::redundant_guards)]
#[macro_use]
extern crate proc_macros;
struct A(u32);
struct B {
e: Option<A>,
}
struct C(u32, u32);
#[derive(PartialEq)]
struct FloatWrapper(f32);
fn issue11304() {
match 0.1 {
x if x == 0.0 => todo!(),
_ => todo!(),
}
match FloatWrapper(0.1) {
x if x == FloatWrapper(0.0) => todo!(),
_ => todo!(),
}
}
fn main() {
let c = C(1, 2);
match c {
C(x, y) if let 1 = y => ..,
_ => todo!(),
};
let x = Some(Some(1));
match x {
Some(x) if matches!(x, Some(1) if true) => ..,
Some(x) if matches!(x, Some(1)) => {
println!("a");
..
},
Some(x) if let Some(1) = x => ..,
Some(x) if x == Some(2) => ..,
// Don't lint, since x is used in the body
Some(x) if let Some(1) = x => {
x;
..
}
_ => todo!(),
};
let y = 1;
match x {
// Don't inline these, since y is not from the pat
Some(x) if matches!(y, 1 if true) => ..,
Some(x) if let 1 = y => ..,
Some(x) if y == 2 => ..,
_ => todo!(),
};
let a = A(1);
match a {
_ if a.0 == 1 => {},
_ => todo!(),
}
let b = B { e: Some(A(0)) };
match b {
B { e } if matches!(e, Some(A(2))) => ..,
_ => todo!(),
};
// Do not lint, since we cannot represent this as a pattern (at least, without a conversion)
let v = Some(vec![1u8, 2, 3]);
match v {
Some(x) if x == [1] => {},
_ => {},
}
external! {
let x = Some(Some(1));
match x {
Some(x) if let Some(1) = x => ..,
_ => todo!(),
};
}
with_span! {
span
let x = Some(Some(1));
match x {
Some(x) if let Some(1) = x => ..,
_ => todo!(),
};
}
}
enum E {
A(&'static str),
B(&'static str),
C(&'static str),
}
fn i() {
match E::A("") {
// Do not lint
E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {},
E::A(y) if y == "not from an or pattern" => {},
_ => {},
};
}
fn h(v: Option<u32>) {
match v {
x if matches!(x, Some(0)) => ..,
_ => ..,
};
}
// Do not lint
fn f(s: Option<std::ffi::OsString>) {
match s {
Some(x) if x == "a" => {},
_ => {},
}
}
struct S {
a: usize,
}
impl PartialEq for S {
fn eq(&self, _: &Self) -> bool {
true
}
}
impl Eq for S {}
static CONST_S: S = S { a: 1 };
fn g(opt_s: Option<S>) {
match opt_s {
Some(x) if x == CONST_S => {},
_ => {},
}
}
|