Skip to content

Commit

Permalink
Remove underscore check for manual_non_exhaustive lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 20, 2023
1 parent 6eb935a commit 7cc506d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 0 additions & 3 deletions clippy_lints/src/manual_non_exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
{
let mut iter = def.variants.iter().filter_map(|v| {
(matches!(v.data, hir::VariantData::Unit(_, _))
&& v.ident.as_str().starts_with('_')
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id))
&& !attr::contains_name(cx.tcx.hir().attrs(item.hir_id()), sym::non_exhaustive))
.then_some((v.def_id, v.span))
Expand All @@ -173,9 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {

fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Path(QPath::Resolved(None, p)) = &e.kind
&& let [.., name] = p.segments
&& let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), id) = p.res
&& name.ident.as_str().starts_with('_')
{
let variant_id = cx.tcx.parent(id);
let enum_id = cx.tcx.parent(variant_id);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_non_exhaustive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum NoDocHidden {
_C,
}

// name of variant with doc hidden does not start with underscore, should be ignored
// name of variant with doc hidden does not start with underscore
enum NoUnderscore {
A,
B,
Expand Down
23 changes: 22 additions & 1 deletion tests/ui/manual_non_exhaustive_enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,26 @@ LL | _C,
= note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]`

error: aborting due to previous error
error: this seems like a manual implementation of the non-exhaustive pattern
--> $DIR/manual_non_exhaustive_enum.rs:30:1
|
LL | enum NoUnderscore {
| ^----------------
| |
| _help: add the attribute: `#[non_exhaustive] enum NoUnderscore`
| |
LL | | A,
LL | | B,
LL | | #[doc(hidden)]
LL | | C,
LL | | }
| |_^
|
help: remove this variant
--> $DIR/manual_non_exhaustive_enum.rs:34:5
|
LL | C,
| ^

error: aborting due to 2 previous errors

0 comments on commit 7cc506d

Please sign in to comment.