Skip to content

Commit a72730e

Browse files
committed
Auto merge of rust-lang#11844 - GuillaumeGomez:manual_non_exhaustive-rm-underscore-check, r=flip1995
Remove underscore check for `manual_non_exhaustive` lint Fixes rust-lang/rust-clippy#10550. As indicated in rust-lang/rust-clippy#10559, the underscore check should be removed. changelog: remove underscore check for `manual_non_exhaustive` lint r? `@blyxyas`
2 parents b21c9d4 + 91fc4b3 commit a72730e

4 files changed

+44
-7
lines changed

clippy_lints/src/manual_non_exhaustive.rs

-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ impl EarlyLintPass for ManualNonExhaustiveStruct {
118118
if let Some(Ok(field)) = iter.next()
119119
&& iter.next().is_none()
120120
&& field.ty.kind.is_unit()
121-
&& field.ident.map_or(true, |name| name.as_str().starts_with('_'))
122121
{
123122
span_lint_and_then(
124123
cx,
@@ -158,7 +157,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
158157
{
159158
let mut iter = def.variants.iter().filter_map(|v| {
160159
(matches!(v.data, hir::VariantData::Unit(_, _))
161-
&& v.ident.as_str().starts_with('_')
162160
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id))
163161
&& !attr::contains_name(cx.tcx.hir().attrs(item.hir_id()), sym::non_exhaustive))
164162
.then_some((v.def_id, v.span))
@@ -173,9 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
173171

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

tests/ui/manual_non_exhaustive_enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum NoDocHidden {
2626
_C,
2727
}
2828

29-
// name of variant with doc hidden does not start with underscore, should be ignored
29+
// name of variant with doc hidden does not start with underscore
3030
enum NoUnderscore {
3131
A,
3232
B,

tests/ui/manual_non_exhaustive_enum.stderr

+22-1
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

tests/ui/manual_non_exhaustive_struct.stderr

+21-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ help: remove this field
3838
LL | _c: (),
3939
| ^^^^^^
4040

41+
error: this seems like a manual implementation of the non-exhaustive pattern
42+
--> $DIR/manual_non_exhaustive_struct.rs:29:5
43+
|
44+
LL | struct NoUnderscore {
45+
| ^------------------
46+
| |
47+
| _____help: add the attribute: `#[non_exhaustive] struct NoUnderscore`
48+
| |
49+
LL | | pub a: i32,
50+
LL | | pub b: i32,
51+
LL | | c: (),
52+
LL | | }
53+
| |_____^
54+
|
55+
help: remove this field
56+
--> $DIR/manual_non_exhaustive_struct.rs:32:9
57+
|
58+
LL | c: (),
59+
| ^^^^^
60+
4161
error: this seems like a manual implementation of the non-exhaustive pattern
4262
--> $DIR/manual_non_exhaustive_struct.rs:56:5
4363
|
@@ -64,5 +84,5 @@ help: remove this field
6484
LL | struct Tp(pub i32, pub i32, ());
6585
| ^^
6686

67-
error: aborting due to 4 previous errors
87+
error: aborting due to 5 previous errors
6888

0 commit comments

Comments
 (0)