Avoid match_wildcard_for_single_variants on guarded wild matches

fix #9993
changlog: [`match_wildcard_for_single_variants`] avoid suggestion on wildcard with guard
This commit is contained in:
koka 2022-12-10 21:05:08 +09:00
parent ef2018cc49
commit 055f349670
No known key found for this signature in database
GPG key ID: A5917A40697774CD
4 changed files with 33 additions and 2 deletions

View file

@ -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);

View file

@ -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(..)

View file

@ -132,3 +132,19 @@ 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,
};
}
}

View file

@ -132,3 +132,19 @@ 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,
};
}
}