1 #![warn(clippy::single_match)]
2 #![allow(clippy::uninlined_format_args)]
18 // Note the missing block braces.
19 // We suggest `if let Some(y) = x { .. }` because the macro
20 // is expanded before we can do anything.
21 Some(y) => println!("{:?}", y),
27 (2..=3, 7..=9) => dummy(),
31 // Not linted (pattern guards used)
33 Some(y) if y == 0 => println!("{:?}", y),
37 // Not linted (no block with statements in the single arm)
39 (2..=3, 7..=9) => println!("{:?}", z),
40 _ => println!("nope"),
51 fn single_match_know_enum() {
53 let y: Result<_, i8> = Ok(1i8);
65 let c = Cow::Borrowed("");
68 Cow::Borrowed(..) => dummy(),
75 Bar => println!("42"),
80 Baz(_) => println!("42"),
93 #[derive(PartialEq, Eq)]
102 Foo::A => println!(),
106 const FOO_C: Foo = Foo::C(0);
113 Foo::A => println!(),
119 Foo::A => println!(),
127 impl PartialEq for Bar {
128 fn eq(&self, rhs: &Self) -> bool {
129 matches!((self, rhs), (Self::A, Self::A) | (Self::B, Self::B))
136 Bar::A => println!(),
154 let x = (Some(E::V), Some(42));
156 // Don't lint, because the `E` enum can be extended with additional fields later. Thus, the
157 // proposed replacement to `if let Some(E::V)` may hide non-exhaustive warnings that appeared
158 // because of `match` construction.
160 (Some(E::V), _) => {},
172 (Some(E::V), _) => todo!(),
177 match (Some(42), Some(E::V), Some(42)) {
178 (.., Some(E::V), _) => {},
182 // Don't lint, see above.
183 match (Some(E::V), Some(E::V), Some(E::V)) {
184 (.., Some(E::V), _) => {},
188 // Don't lint, see above.
189 match (Some(E::V), Some(E::V), Some(E::V)) {
190 (Some(E::V), ..) => {},
194 // Don't lint, see above.
195 match (Some(E::V), Some(E::V), Some(E::V)) {
196 (_, Some(E::V), ..) => {},
201 fn skip_type_aliases() {
211 use OptionEx::{None, Some};
212 use ResultEx::{Err, Ok};
227 macro_rules! single_match {
230 15 => println!("15"),
240 let _ = match Some(0) {
241 #[cfg(feature = "foo")]