mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
Auto merge of #10056 - koka831:fix/9993, r=Jarcho
Avoid `match_wildcard_for_single_variants` on guarded wild matches fix #9993 changelog: FP: [`match_wildcard_for_single_variants`]: No longer lints on wildcards with a guard [#10056](https://github.com/rust-lang/rust-clippy/pull/10056) <!-- changelog_checked --> r? `@Jarcho`
This commit is contained in:
commit
8a6e6fd623
5 changed files with 52 additions and 3 deletions
|
@ -30,7 +30,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
|
|||
let mut has_non_wild = false;
|
||||
for arm in arms {
|
||||
match peel_hir_pat_refs(arm.pat).0.kind {
|
||||
PatKind::Wild => wildcard_span = Some(arm.pat.span),
|
||||
PatKind::Wild if arm.guard.is_none() => wildcard_span = Some(arm.pat.span),
|
||||
PatKind::Binding(_, _, ident, None) => {
|
||||
wildcard_span = Some(arm.pat.span);
|
||||
wildcard_ident = Some(ident);
|
||||
|
|
|
@ -185,7 +185,6 @@ impl<'a> Sugg<'a> {
|
|||
) -> Self {
|
||||
use rustc_ast::ast::RangeLimits;
|
||||
|
||||
#[expect(clippy::match_wildcard_for_single_variants)]
|
||||
match expr.kind {
|
||||
_ if expr.span.ctxt() != ctxt => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0),
|
||||
ast::ExprKind::AddrOf(..)
|
||||
|
|
|
@ -132,3 +132,25 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod issue9993 {
|
||||
enum Foo {
|
||||
A(bool),
|
||||
B,
|
||||
}
|
||||
|
||||
fn test() {
|
||||
let _ = match Foo::A(true) {
|
||||
_ if false => 0,
|
||||
Foo::A(true) => 1,
|
||||
Foo::A(false) => 2,
|
||||
Foo::B => 3,
|
||||
};
|
||||
|
||||
let _ = match Foo::B {
|
||||
_ if false => 0,
|
||||
Foo::A(_) => 1,
|
||||
Foo::B => 2,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,3 +132,25 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod issue9993 {
|
||||
enum Foo {
|
||||
A(bool),
|
||||
B,
|
||||
}
|
||||
|
||||
fn test() {
|
||||
let _ = match Foo::A(true) {
|
||||
_ if false => 0,
|
||||
Foo::A(true) => 1,
|
||||
Foo::A(false) => 2,
|
||||
Foo::B => 3,
|
||||
};
|
||||
|
||||
let _ = match Foo::B {
|
||||
_ if false => 0,
|
||||
Foo::A(_) => 1,
|
||||
_ => 2,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,5 +48,11 @@ error: wildcard matches only a single variant and will also match any future add
|
|||
LL | _ => (),
|
||||
| ^ help: try this: `Color::Blue`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: wildcard matches only a single variant and will also match any future added variants
|
||||
--> $DIR/match_wildcard_for_single_variants.rs:153:13
|
||||
|
|
||||
LL | _ => 2,
|
||||
| ^ help: try this: `Foo::B`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue