Remove underscore check for manual_non_exhaustive lint

This commit is contained in:
Guillaume Gomez 2023-11-20 14:09:02 +01:00
parent 6eb935a578
commit 91fc4b3001
4 changed files with 44 additions and 7 deletions

View file

@ -118,7 +118,6 @@ impl EarlyLintPass for ManualNonExhaustiveStruct {
if let Some(Ok(field)) = iter.next()
&& iter.next().is_none()
&& field.ty.kind.is_unit()
&& field.ident.map_or(true, |name| name.as_str().starts_with('_'))
{
span_lint_and_then(
cx,
@ -158,7 +157,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))
@ -173,9 +171,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);