Skip to content

Commit 46fec12

Browse files
committed
wildcard_enum_match_arm lint takes the enum origin into account
1 parent 1480cea commit 46fec12

5 files changed

+13
-6
lines changed

clippy_lints/src/matches/match_wild_enum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,6 @@ impl<'a> CommonPrefixSearcher<'a> {
192192
}
193193

194194
fn is_hidden(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool {
195-
cx.tcx.is_doc_hidden(variant_def.def_id) || cx.tcx.has_attr(variant_def.def_id, sym::unstable)
195+
(cx.tcx.is_doc_hidden(variant_def.def_id) || cx.tcx.has_attr(variant_def.def_id, sym::unstable))
196+
&& !variant_def.def_id.as_local().is_some()
196197
}

tests/ui/match_wildcard_for_single_variants.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn main() {
123123
Enum::A => (),
124124
Enum::B => (),
125125
Enum::C => (),
126-
_ => (),
126+
Enum::__Private => (),
127127
}
128128
match Enum::A {
129129
Enum::A => (),

tests/ui/match_wildcard_for_single_variants.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ error: wildcard matches only a single variant and will also match any future add
4848
LL | _ => (),
4949
| ^ help: try this: `Color::Blue`
5050

51+
error: wildcard matches only a single variant and will also match any future added variants
52+
--> $DIR/match_wildcard_for_single_variants.rs:126:13
53+
|
54+
LL | _ => (),
55+
| ^ help: try this: `Enum::__Private`
56+
5157
error: wildcard matches only a single variant and will also match any future added variants
5258
--> $DIR/match_wildcard_for_single_variants.rs:153:13
5359
|
5460
LL | _ => 2,
5561
| ^ help: try this: `Foo::B`
5662

57-
error: aborting due to 9 previous errors
63+
error: aborting due to 10 previous errors
5864

tests/ui/wildcard_enum_match_arm.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() {
9696
}
9797
match Enum::A {
9898
Enum::A => (),
99-
Enum::B | _ => (),
99+
Enum::B | Enum::__Private => (),
100100
}
101101
}
102102
}

tests/ui/wildcard_enum_match_arm.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ error: wildcard matches known variants and will also match future added variants
3434
LL | _ => {},
3535
| ^ help: try this: `ErrorKind::PermissionDenied | _`
3636

37-
error: wildcard matches known variants and will also match future added variants
37+
error: wildcard match will also match any future added variants
3838
--> $DIR/wildcard_enum_match_arm.rs:99:13
3939
|
4040
LL | _ => (),
41-
| ^ help: try this: `Enum::B | _`
41+
| ^ help: try this: `Enum::B | Enum::__Private`
4242

4343
error: aborting due to 6 previous errors
4444

0 commit comments

Comments
 (0)