about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibsG <thibsg@pm.me>2021-10-14 12:16:35 +0200
committerThibsG <thibsg@pm.me>2021-10-20 17:53:05 +0200
commit3630afb57f5c98c83210adde07a92f6ebdce7fc7 (patch)
tree79f508cfb60e1801275ba9ea3bcca7ecb61b8ded
parent22144c02c2d790c2e3b74dc0363000511284f6d8 (diff)
downloadrust-3630afb57f5c98c83210adde07a92f6ebdce7fc7.tar.gz
rust-3630afb57f5c98c83210adde07a92f6ebdce7fc7.zip
Do not lint if any parent has hidden attribute
-rw-r--r--clippy_lints/src/doc.rs12
-rw-r--r--tests/ui/doc_unsafe.rs10
2 files changed, 22 insertions, 0 deletions
diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs
index 9840affbf6f..5511c3ea9b6 100644
--- a/clippy_lints/src/doc.rs
+++ b/clippy_lints/src/doc.rs
@@ -1,3 +1,4 @@
+use clippy_utils::attrs::is_doc_hidden;
 use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note};
 use clippy_utils::source::first_line_of_span;
 use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
@@ -297,6 +298,17 @@ fn lint_for_missing_headers<'tcx>(
     if !cx.access_levels.is_exported(def_id) {
         return; // Private functions do not require doc comments
     }
+
+    // do not lint if any parent has `#[doc(hidden)]` attribute (#7347)
+    if cx
+        .tcx
+        .hir()
+        .parent_iter(cx.tcx.hir().local_def_id_to_hir_id(def_id))
+        .any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
+    {
+        return;
+    }
+
     if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
         span_lint(
             cx,
diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs
index 8f823f1672b..03bb30f9083 100644
--- a/tests/ui/doc_unsafe.rs
+++ b/tests/ui/doc_unsafe.rs
@@ -115,3 +115,13 @@ fn main() {
         drive();
     }
 }
+
+// do not lint if any parent has `#[doc(hidden)]` attribute
+// see #7347
+#[doc(hidden)]
+pub mod __macro {
+    pub struct T;
+    impl T {
+        pub unsafe fn f() {}
+    }
+}