From db539d051d2204521c1fb914c91e5e55d4e0b4be Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 21 Jun 2025 18:30:55 +0200 Subject: [PATCH] Add missing space when expanding a struct-like variant In `wildcard_enum_match_arm`, expanding a variant with struct-like fields was missing a space between the variant name and the opening bracket. Also, add a test for tuple-like variants with only one field, as those are expanded as `VariantName(_)` instead of `VariantName(..)`. --- clippy_lints/src/matches/match_wild_enum.rs | 2 +- tests/ui/wildcard_enum_match_arm.fixed | 15 +++++++++++++++ tests/ui/wildcard_enum_match_arm.rs | 15 +++++++++++++++ tests/ui/wildcard_enum_match_arm.stderr | 10 ++++++++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/matches/match_wild_enum.rs b/clippy_lints/src/matches/match_wild_enum.rs index d9e5b07221d7..70a03ff93762 100644 --- a/clippy_lints/src/matches/match_wild_enum.rs +++ b/clippy_lints/src/matches/match_wild_enum.rs @@ -140,7 +140,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { Some(CtorKind::Fn) if variant.fields.len() == 1 => "(_)", Some(CtorKind::Fn) => "(..)", Some(CtorKind::Const) => "", - None => "{ .. }", + None => " { .. }", } ) }; diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index e40e52673832..5f738a254dcd 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -90,6 +90,21 @@ fn main() { _ => {}, } + { + pub enum Enum { + A, + B, + C(u8), + D(u8, u8), + E { e: u8 }, + }; + match Enum::A { + Enum::A => (), + Enum::B | Enum::C(_) | Enum::D(..) | Enum::E { .. } => (), + //~^ wildcard_enum_match_arm + } + } + { #![allow(clippy::manual_non_exhaustive)] pub enum Enum { diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 8259f0598470..4bc4bfdcb794 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -90,6 +90,21 @@ fn main() { _ => {}, } + { + pub enum Enum { + A, + B, + C(u8), + D(u8, u8), + E { e: u8 }, + }; + match Enum::A { + Enum::A => (), + _ => (), + //~^ wildcard_enum_match_arm + } + } + { #![allow(clippy::manual_non_exhaustive)] pub enum Enum { diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index 1f1de166d001..d0929989494a 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -37,14 +37,20 @@ LL | _ => {}, error: wildcard match will also match any future added variants --> tests/ui/wildcard_enum_match_arm.rs:103:13 | +LL | _ => (), + | ^ help: try: `Enum::B | Enum::C(_) | Enum::D(..) | Enum::E { .. }` + +error: wildcard match will also match any future added variants + --> tests/ui/wildcard_enum_match_arm.rs:118:13 + | LL | _ => (), | ^ help: try: `Enum::B | Enum::__Private` error: wildcard match will also match any future added variants - --> tests/ui/wildcard_enum_match_arm.rs:118:9 + --> tests/ui/wildcard_enum_match_arm.rs:133:9 | LL | r#type => {}, | ^^^^^^ help: try: `r#type @ Foo::B | r#type @ Foo::C` -error: aborting due to 7 previous errors +error: aborting due to 8 previous errors