don't lint nested items that don't have generated documentation in missing_docs_in_private_items

This commit is contained in:
y21 2024-10-20 23:42:28 +02:00
parent 2f71ce6651
commit b3bf128e54
3 changed files with 31 additions and 1 deletions

View File

@ -12,6 +12,7 @@
use clippy_utils::source::SpanRangeExt;
use rustc_ast::ast::{self, MetaItem, MetaItemKind};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::Visibility;
@ -111,6 +112,21 @@ fn check_missing_docs_attrs(
return;
}
if let Some(parent_def_id) = cx.tcx.opt_parent(def_id.to_def_id())
&& let DefKind::AnonConst
| DefKind::AssocConst
| DefKind::AssocFn
| DefKind::Closure
| DefKind::Const
| DefKind::Fn
| DefKind::InlineConst
| DefKind::Static { .. }
| DefKind::SyntheticCoroutineBody = cx.tcx.def_kind(parent_def_id)
{
// Nested item has no generated documentation, so it doesn't need to be documented.
return;
}
let has_doc = attrs
.iter()
.any(|a| a.doc_str().is_some() || Self::has_include(a.meta()))

View File

@ -119,6 +119,11 @@ fn main() {}
// Don't lint unnamed constants
const _: () = ();
fn issue13298() {
// Rustdoc doesn't generate documentation for items within other items like fns or consts
const MSG: &str = "Hello, world!";
}
// issue #12197
// Undocumented field originated inside of spanned proc-macro attribute
/// Some dox for struct.

View File

@ -88,5 +88,14 @@ error: missing documentation for a function
LL | fn also_undocumented2() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 13 previous errors
error: missing documentation for a function
--> tests/ui/missing_doc.rs:122:1
|
LL | / fn issue13298() {
LL | | // Rustdoc doesn't generate documentation for items within other items like fns or consts
LL | | const MSG: &str = "Hello, world!";
LL | | }
| |_^
error: aborting due to 14 previous errors