Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6427ba4

Browse files
committed
Fix #[expect] for clippy::manual_non_exhaustive
1 parent 525f5ee commit 6427ba4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use clippy_utils::diagnostics::span_lint_and_then;
1+
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
22
use clippy_utils::source::snippet_opt;
3-
use clippy_utils::{is_doc_hidden, is_lint_allowed, meets_msrv, msrvs};
3+
use clippy_utils::{is_doc_hidden, meets_msrv, msrvs};
44
use rustc_ast::ast::{self, VisibilityKind};
55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_errors::Applicability;
@@ -190,12 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
190190
!self
191191
.constructed_enum_variants
192192
.contains(&(enum_id.to_def_id(), variant_id.to_def_id()))
193-
&& !is_lint_allowed(cx, MANUAL_NON_EXHAUSTIVE, cx.tcx.hir().local_def_id_to_hir_id(enum_id))
194193
})
195194
{
196-
span_lint_and_then(
195+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(enum_id);
196+
span_lint_hir_and_then(
197197
cx,
198198
MANUAL_NON_EXHAUSTIVE,
199+
hir_id,
199200
enum_span,
200201
"this seems like a manual implementation of the non-exhaustive pattern",
201202
|diag| {

tests/ui/manual_non_exhaustive_enum.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(lint_reasons)]
12
#![warn(clippy::manual_non_exhaustive)]
23
#![allow(unused)]
34

@@ -75,4 +76,12 @@ fn foo(x: &mut UsedHidden) {
7576
}
7677
}
7778

79+
#[expect(clippy::manual_non_exhaustive)]
80+
enum ExpectLint {
81+
A,
82+
B,
83+
#[doc(hidden)]
84+
_C,
85+
}
86+
7887
fn main() {}

tests/ui/manual_non_exhaustive_enum.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this seems like a manual implementation of the non-exhaustive pattern
2-
--> $DIR/manual_non_exhaustive_enum.rs:4:1
2+
--> $DIR/manual_non_exhaustive_enum.rs:5:1
33
|
44
LL | enum E {
55
| ^-----
@@ -15,13 +15,13 @@ LL | | }
1515
|
1616
= note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
1717
help: remove this variant
18-
--> $DIR/manual_non_exhaustive_enum.rs:8:5
18+
--> $DIR/manual_non_exhaustive_enum.rs:9:5
1919
|
2020
LL | _C,
2121
| ^^
2222

2323
error: this seems like a manual implementation of the non-exhaustive pattern
24-
--> $DIR/manual_non_exhaustive_enum.rs:13:1
24+
--> $DIR/manual_non_exhaustive_enum.rs:14:1
2525
|
2626
LL | / enum Ep {
2727
LL | | A,
@@ -32,7 +32,7 @@ LL | | }
3232
| |_^
3333
|
3434
help: remove this variant
35-
--> $DIR/manual_non_exhaustive_enum.rs:17:5
35+
--> $DIR/manual_non_exhaustive_enum.rs:18:5
3636
|
3737
LL | _C,
3838
| ^^

0 commit comments

Comments
 (0)