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
This commit is contained in:
Timo 2025-06-21 17:22:37 +00:00 committed by GitHub
commit 76118ec84e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 3 deletions

View file

@ -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 => " { .. }",
}
)
};

View file

@ -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 {

View file

@ -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 {

View file

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