Skip to content

Commit db539d0

Browse files
committed
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(..)`.
1 parent a421ffb commit db539d0

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

clippy_lints/src/matches/match_wild_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
140140
Some(CtorKind::Fn) if variant.fields.len() == 1 => "(_)",
141141
Some(CtorKind::Fn) => "(..)",
142142
Some(CtorKind::Const) => "",
143-
None => "{ .. }",
143+
None => " { .. }",
144144
}
145145
)
146146
};

tests/ui/wildcard_enum_match_arm.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ fn main() {
9090
_ => {},
9191
}
9292

93+
{
94+
pub enum Enum {
95+
A,
96+
B,
97+
C(u8),
98+
D(u8, u8),
99+
E { e: u8 },
100+
};
101+
match Enum::A {
102+
Enum::A => (),
103+
Enum::B | Enum::C(_) | Enum::D(..) | Enum::E { .. } => (),
104+
//~^ wildcard_enum_match_arm
105+
}
106+
}
107+
93108
{
94109
#![allow(clippy::manual_non_exhaustive)]
95110
pub enum Enum {

tests/ui/wildcard_enum_match_arm.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ fn main() {
9090
_ => {},
9191
}
9292

93+
{
94+
pub enum Enum {
95+
A,
96+
B,
97+
C(u8),
98+
D(u8, u8),
99+
E { e: u8 },
100+
};
101+
match Enum::A {
102+
Enum::A => (),
103+
_ => (),
104+
//~^ wildcard_enum_match_arm
105+
}
106+
}
107+
93108
{
94109
#![allow(clippy::manual_non_exhaustive)]
95110
pub enum Enum {

tests/ui/wildcard_enum_match_arm.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@ LL | _ => {},
3737
error: wildcard match will also match any future added variants
3838
--> tests/ui/wildcard_enum_match_arm.rs:103:13
3939
|
40+
LL | _ => (),
41+
| ^ help: try: `Enum::B | Enum::C(_) | Enum::D(..) | Enum::E { .. }`
42+
43+
error: wildcard match will also match any future added variants
44+
--> tests/ui/wildcard_enum_match_arm.rs:118:13
45+
|
4046
LL | _ => (),
4147
| ^ help: try: `Enum::B | Enum::__Private`
4248

4349
error: wildcard match will also match any future added variants
44-
--> tests/ui/wildcard_enum_match_arm.rs:118:9
50+
--> tests/ui/wildcard_enum_match_arm.rs:133:9
4551
|
4652
LL | r#type => {},
4753
| ^^^^^^ help: try: `r#type @ Foo::B | r#type @ Foo::C`
4854

49-
error: aborting due to 7 previous errors
55+
error: aborting due to 8 previous errors
5056

0 commit comments

Comments
 (0)