mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
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:
parent
ef2018cc49
commit
055f349670
4 changed files with 33 additions and 2 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,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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue