Skip to content

Commit 8c7c08e

Browse files
Remove underscore check for manual_non_exhaustive lint
1 parent 6eb935a commit 8c7c08e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
158158
{
159159
let mut iter = def.variants.iter().filter_map(|v| {
160160
(matches!(v.data, hir::VariantData::Unit(_, _))
161-
&& v.ident.as_str().starts_with('_')
162161
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id))
163162
&& !attr::contains_name(cx.tcx.hir().attrs(item.hir_id()), sym::non_exhaustive))
164163
.then_some((v.def_id, v.span))
@@ -173,9 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
173172

174173
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
175174
if let ExprKind::Path(QPath::Resolved(None, p)) = &e.kind
176-
&& let [.., name] = p.segments
177175
&& let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), id) = p.res
178-
&& name.ident.as_str().starts_with('_')
179176
{
180177
let variant_id = cx.tcx.parent(id);
181178
let enum_id = cx.tcx.parent(variant_id);

tests/ui/manual_non_exhaustive_enum.stderr

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,26 @@ LL | _C,
2222
= note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
2323
= help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]`
2424

25-
error: aborting due to previous error
25+
error: this seems like a manual implementation of the non-exhaustive pattern
26+
--> $DIR/manual_non_exhaustive_enum.rs:30:1
27+
|
28+
LL | enum NoUnderscore {
29+
| ^----------------
30+
| |
31+
| _help: add the attribute: `#[non_exhaustive] enum NoUnderscore`
32+
| |
33+
LL | | A,
34+
LL | | B,
35+
LL | | #[doc(hidden)]
36+
LL | | C,
37+
LL | | }
38+
| |_^
39+
|
40+
help: remove this variant
41+
--> $DIR/manual_non_exhaustive_enum.rs:34:5
42+
|
43+
LL | C,
44+
| ^
45+
46+
error: aborting due to 2 previous errors
2647

0 commit comments

Comments
 (0)