about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/manual_non_exhaustive.rs9
-rw-r--r--tests/ui/manual_non_exhaustive_enum.rs9
-rw-r--r--tests/ui/manual_non_exhaustive_enum.stderr8
3 files changed, 18 insertions, 8 deletions
diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs
index 14f5faafd7c..4278e98dc91 100644
--- a/clippy_lints/src/manual_non_exhaustive.rs
+++ b/clippy_lints/src/manual_non_exhaustive.rs
@@ -1,6 +1,6 @@
-use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
 use clippy_utils::source::snippet_opt;
-use clippy_utils::{is_doc_hidden, is_lint_allowed, meets_msrv, msrvs};
+use clippy_utils::{is_doc_hidden, meets_msrv, msrvs};
 use rustc_ast::ast::{self, VisibilityKind};
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::Applicability;
@@ -190,12 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
                 !self
                     .constructed_enum_variants
                     .contains(&(enum_id.to_def_id(), variant_id.to_def_id()))
-                    && !is_lint_allowed(cx, MANUAL_NON_EXHAUSTIVE, cx.tcx.hir().local_def_id_to_hir_id(enum_id))
             })
         {
-            span_lint_and_then(
+            let hir_id = cx.tcx.hir().local_def_id_to_hir_id(enum_id);
+            span_lint_hir_and_then(
                 cx,
                 MANUAL_NON_EXHAUSTIVE,
+                hir_id,
                 enum_span,
                 "this seems like a manual implementation of the non-exhaustive pattern",
                 |diag| {
diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs
index f23c6d69b4c..03b2433f666 100644
--- a/tests/ui/manual_non_exhaustive_enum.rs
+++ b/tests/ui/manual_non_exhaustive_enum.rs
@@ -1,3 +1,4 @@
+#![feature(lint_reasons)]
 #![warn(clippy::manual_non_exhaustive)]
 #![allow(unused)]
 
@@ -75,4 +76,12 @@ fn foo(x: &mut UsedHidden) {
     }
 }
 
+#[expect(clippy::manual_non_exhaustive)]
+enum ExpectLint {
+    A,
+    B,
+    #[doc(hidden)]
+    _C,
+}
+
 fn main() {}
diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr
index 317a45d2cbd..144fe86df55 100644
--- a/tests/ui/manual_non_exhaustive_enum.stderr
+++ b/tests/ui/manual_non_exhaustive_enum.stderr
@@ -1,5 +1,5 @@
 error: this seems like a manual implementation of the non-exhaustive pattern
-  --> $DIR/manual_non_exhaustive_enum.rs:4:1
+  --> $DIR/manual_non_exhaustive_enum.rs:5:1
    |
 LL |   enum E {
    |   ^-----
@@ -15,13 +15,13 @@ LL | | }
    |
    = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
 help: remove this variant
-  --> $DIR/manual_non_exhaustive_enum.rs:8:5
+  --> $DIR/manual_non_exhaustive_enum.rs:9:5
    |
 LL |     _C,
    |     ^^
 
 error: this seems like a manual implementation of the non-exhaustive pattern
-  --> $DIR/manual_non_exhaustive_enum.rs:13:1
+  --> $DIR/manual_non_exhaustive_enum.rs:14:1
    |
 LL | / enum Ep {
 LL | |     A,
@@ -32,7 +32,7 @@ LL | | }
    | |_^
    |
 help: remove this variant
-  --> $DIR/manual_non_exhaustive_enum.rs:17:5
+  --> $DIR/manual_non_exhaustive_enum.rs:18:5
    |
 LL |     _C,
    |     ^^