diff options
| author | Timo <30553356+y21@users.noreply.github.com> | 2025-06-21 17:22:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-21 17:22:37 +0000 |
| commit | 76118ec84ee5c1e865d10cd5d99c02878dd56ade (patch) | |
| tree | 63c50be7ba1031aa314ec805652b2c4065e5169e | |
| parent | a421ffbadb2b1de1ec570f2c763b25fbd3aed9d5 (diff) | |
| parent | db539d051d2204521c1fb914c91e5e55d4e0b4be (diff) | |
| download | rust-76118ec84ee5c1e865d10cd5d99c02878dd56ade.tar.gz rust-76118ec84ee5c1e865d10cd5d99c02878dd56ade.zip | |
Add missing space when expanding a struct-like variant (#15096)
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(..)`. changelog: none
| -rw-r--r-- | clippy_lints/src/matches/match_wild_enum.rs | 2 | ||||
| -rw-r--r-- | tests/ui/wildcard_enum_match_arm.fixed | 15 | ||||
| -rw-r--r-- | tests/ui/wildcard_enum_match_arm.rs | 15 | ||||
| -rw-r--r-- | 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 d9e5b07221d..70a03ff9376 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 e40e5267383..5f738a254dc 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -91,6 +91,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 { A, diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 8259f059847..4bc4bfdcb79 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -91,6 +91,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 { A, diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index 1f1de166d00..d0929989494 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -38,13 +38,19 @@ 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 |
