Skip to content

Commit b3bf128

Browse files
committed
don't lint nested items that don't have generated documentation in missing_docs_in_private_items
1 parent 2f71ce6 commit b3bf128

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

clippy_lints/src/missing_doc.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use clippy_utils::is_from_proc_macro;
1212
use clippy_utils::source::SpanRangeExt;
1313
use rustc_ast::ast::{self, MetaItem, MetaItemKind};
1414
use rustc_hir as hir;
15+
use rustc_hir::def::DefKind;
1516
use rustc_hir::def_id::LocalDefId;
1617
use rustc_lint::{LateContext, LateLintPass, LintContext};
1718
use rustc_middle::ty::Visibility;
@@ -111,6 +112,21 @@ impl MissingDoc {
111112
return;
112113
}
113114

115+
if let Some(parent_def_id) = cx.tcx.opt_parent(def_id.to_def_id())
116+
&& let DefKind::AnonConst
117+
| DefKind::AssocConst
118+
| DefKind::AssocFn
119+
| DefKind::Closure
120+
| DefKind::Const
121+
| DefKind::Fn
122+
| DefKind::InlineConst
123+
| DefKind::Static { .. }
124+
| DefKind::SyntheticCoroutineBody = cx.tcx.def_kind(parent_def_id)
125+
{
126+
// Nested item has no generated documentation, so it doesn't need to be documented.
127+
return;
128+
}
129+
114130
let has_doc = attrs
115131
.iter()
116132
.any(|a| a.doc_str().is_some() || Self::has_include(a.meta()))

tests/ui/missing_doc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ with_span!(span pub const FOO2_PM: u32 = 0;);
119119
// Don't lint unnamed constants
120120
const _: () = ();
121121

122+
fn issue13298() {
123+
// Rustdoc doesn't generate documentation for items within other items like fns or consts
124+
const MSG: &str = "Hello, world!";
125+
}
126+
122127
// issue #12197
123128
// Undocumented field originated inside of spanned proc-macro attribute
124129
/// Some dox for struct.

tests/ui/missing_doc.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,14 @@ error: missing documentation for a function
8888
LL | fn also_undocumented2() {}
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
9090

91-
error: aborting due to 13 previous errors
91+
error: missing documentation for a function
92+
--> tests/ui/missing_doc.rs:122:1
93+
|
94+
LL | / fn issue13298() {
95+
LL | | // Rustdoc doesn't generate documentation for items within other items like fns or consts
96+
LL | | const MSG: &str = "Hello, world!";
97+
LL | | }
98+
| |_^
99+
100+
error: aborting due to 14 previous errors
92101

0 commit comments

Comments
 (0)