2 #![warn(clippy::single_match)]
5 clippy
::uninlined_format_args
,
7 clippy
::redundant_guards
,
8 clippy
::redundant_pattern_matching
24 // Note the missing block braces.
25 // We suggest `if let Some(y) = x { .. }` because the macro
26 // is expanded before we can do anything.
27 Some(y
) => println
!("{:?}", y
),
33 (2..=3, 7..=9) => dummy(),
37 // Not linted (pattern guards used)
39 Some(y
) if y
== 0 => println
!("{:?}", y
),
43 // Not linted (no block with statements in the single arm)
45 (2..=3, 7..=9) => println
!("{:?}", z
),
46 _
=> println
!("nope"),
57 fn single_match_know_enum() {
59 let y
: Result
<_
, i8> = Ok(1i8);
71 let c
= Cow
::Borrowed("");
74 Cow
::Borrowed(..) => dummy(),
81 Bar
=> println
!("42"),
86 Baz(_
) => println
!("42"),
99 #[derive(PartialEq, Eq)]
108 Foo
::A
=> println
!(),
112 const FOO_C
: Foo
= Foo
::C(0);
119 Foo
::A
=> println
!(),
125 Foo
::A
=> println
!(),
133 impl PartialEq
for Bar
{
134 fn eq(&self, rhs
: &Self) -> bool
{
135 matches
!((self, rhs
), (Self::A
, Self::A
) | (Self::B
, Self::B
))
142 Bar
::A
=> println
!(),
160 let x
= (Some(E
::V
), Some(42));
162 // Don't lint, because the `E` enum can be extended with additional fields later. Thus, the
163 // proposed replacement to `if let Some(E::V)` may hide non-exhaustive warnings that appeared
164 // because of `match` construction.
166 (Some(E
::V
), _
) => {}
,
178 (Some(E
::V
), _
) => todo
!(),
183 match (Some(42), Some(E
::V
), Some(42)) {
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
), ..) => {}
,
200 // Don't lint, see above.
201 match (Some(E
::V
), Some(E
::V
), Some(E
::V
)) {
202 (_
, Some(E
::V
), ..) => {}
,
207 fn skip_type_aliases() {
217 use OptionEx
::{None, Some}
;
218 use ResultEx
::{Err, Ok}
;
233 macro_rules
! single_match
{
236 15 => println
!("15"),
246 let _
= match Some(0) {
247 #[cfg(feature = "foo")]
254 fn issue_10808(bar
: Option
<i32>) {
257 let r
= &v
as *const i32;
267 let r
= &v
as *const i32;
276 struct SomeError(i32, i32);
278 fn foo(x
: Result
<i32, ()>) {
281 println
!("Yay! {y}");
284 // Ignore this error because blah blah blah.
289 fn bar(x
: Result
<i32, SomeError
>) {
292 println
!("Yay! {y}");
295 // TODO: Process the error properly.
300 fn block_comment(x
: Result
<i32, SomeError
>) {
303 println
!("Yay! {y}");
307 let's make sure that this also
308 does not lint block comments.