1 #![warn(clippy::single_match)]
17 // Note the missing block braces.
18 // We suggest `if let Some(y) = x { .. }` because the macro
19 // is expanded before we can do anything.
20 Some(y) => println!("{:?}", y),
26 (2..=3, 7..=9) => dummy(),
30 // Not linted (pattern guards used)
32 Some(y) if y == 0 => println!("{:?}", y),
36 // Not linted (no block with statements in the single arm)
38 (2..=3, 7..=9) => println!("{:?}", z),
39 _ => println!("nope"),
50 fn single_match_know_enum() {
52 let y: Result<_, i8> = Ok(1i8);
64 let c = Cow::Borrowed("");
67 Cow::Borrowed(..) => dummy(),
74 Bar => println!("42"),
79 Baz(_) => println!("42"),
92 #[derive(PartialEq, Eq)]
101 Foo::A => println!(),
105 const FOO_C: Foo = Foo::C(0);
112 Foo::A => println!(),
118 Foo::A => println!(),
126 impl PartialEq for Bar {
127 fn eq(&self, rhs: &Self) -> bool {
128 matches!((self, rhs), (Self::A, Self::A) | (Self::B, Self::B))
135 Bar::A => println!(),
153 let x = (Some(E::V), Some(42));
155 // Don't lint, because the `E` enum can be extended with additional fields later. Thus, the
156 // proposed replacement to `if let Some(E::V)` may hide non-exhaustive warnings that appeared
157 // because of `match` construction.
159 (Some(E::V), _) => {},
171 (Some(E::V), _) => todo!(),
176 match (Some(42), Some(E::V), Some(42)) {
177 (.., Some(E::V), _) => {},
181 // Don't lint, see above.
182 match (Some(E::V), Some(E::V), Some(E::V)) {
183 (.., Some(E::V), _) => {},
187 // Don't lint, see above.
188 match (Some(E::V), Some(E::V), Some(E::V)) {
189 (Some(E::V), ..) => {},
193 // Don't lint, see above.
194 match (Some(E::V), Some(E::V), Some(E::V)) {
195 (_, Some(E::V), ..) => {},
200 fn skip_type_aliases() {
210 use OptionEx::{None, Some};
211 use ResultEx::{Err, Ok};
226 macro_rules! single_match {
229 15 => println!("15"),
239 let _ = match Some(0) {
240 #[cfg(feature = "foo")]