Skip to content

Commit f11905a

Browse files
committed
Auto merge of #7849 - ThibsG:SafetyDoc, r=llogiq
FIx FP in `missing_safety_doc` lint Fix FP where lint souldn't fire if any parent has `#[doc(hidden)]` attribute fixes: #7347 changelog: [`missing_safety_doc`] Fix FP if any parent has `#[doc(hidden)]` attribute
2 parents 76150a4 + 3630afb commit f11905a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clippy_lints/src/doc.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clippy_utils::attrs::is_doc_hidden;
12
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note};
23
use clippy_utils::source::first_line_of_span;
34
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
@@ -297,6 +298,17 @@ fn lint_for_missing_headers<'tcx>(
297298
if !cx.access_levels.is_exported(def_id) {
298299
return; // Private functions do not require doc comments
299300
}
301+
302+
// do not lint if any parent has `#[doc(hidden)]` attribute (#7347)
303+
if cx
304+
.tcx
305+
.hir()
306+
.parent_iter(cx.tcx.hir().local_def_id_to_hir_id(def_id))
307+
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
308+
{
309+
return;
310+
}
311+
300312
if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
301313
span_lint(
302314
cx,

tests/ui/doc_unsafe.rs

+10
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ fn main() {
115115
drive();
116116
}
117117
}
118+
119+
// do not lint if any parent has `#[doc(hidden)]` attribute
120+
// see #7347
121+
#[doc(hidden)]
122+
pub mod __macro {
123+
pub struct T;
124+
impl T {
125+
pub unsafe fn f() {}
126+
}
127+
}

0 commit comments

Comments
 (0)