Auto merge of #11844 - GuillaumeGomez:manual_non_exhaustive-rm-underscore-check, r=flip1995
Remove underscore check for `manual_non_exhaustive` lint Fixes https://github.com/rust-lang/rust-clippy/issues/10550. As indicated in https://github.com/rust-lang/rust-clippy/pull/10559, the underscore check should be removed. changelog: remove underscore check for `manual_non_exhaustive` lint r? `@blyxyas`
This commit is contained in:
commit
a72730e9a1
@ -118,7 +118,6 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
|
||||
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 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
{
|
||||
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 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -38,6 +38,26 @@ help: remove this field
|
||||
LL | _c: (),
|
||||
| ^^^^^^
|
||||
|
||||
error: this seems like a manual implementation of the non-exhaustive pattern
|
||||
--> $DIR/manual_non_exhaustive_struct.rs:29:5
|
||||
|
|
||||
LL | struct NoUnderscore {
|
||||
| ^------------------
|
||||
| |
|
||||
| _____help: add the attribute: `#[non_exhaustive] struct NoUnderscore`
|
||||
| |
|
||||
LL | | pub a: i32,
|
||||
LL | | pub b: i32,
|
||||
LL | | c: (),
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: remove this field
|
||||
--> $DIR/manual_non_exhaustive_struct.rs:32:9
|
||||
|
|
||||
LL | c: (),
|
||||
| ^^^^^
|
||||
|
||||
error: this seems like a manual implementation of the non-exhaustive pattern
|
||||
--> $DIR/manual_non_exhaustive_struct.rs:56:5
|
||||
|
|
||||
@ -64,5 +84,5 @@ help: remove this field
|
||||
LL | struct Tp(pub i32, pub i32, ());
|
||||
| ^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user