File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use clippy_utils::is_from_proc_macro;
1212use clippy_utils:: source:: SpanRangeExt ;
1313use rustc_ast:: ast:: { self , MetaItem , MetaItemKind } ;
1414use rustc_hir as hir;
15+ use rustc_hir:: def:: DefKind ;
1516use rustc_hir:: def_id:: LocalDefId ;
1617use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
1718use 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 ( ) ) )
Original file line number Diff line number Diff line change @@ -119,6 +119,11 @@ with_span!(span pub const FOO2_PM: u32 = 0;);
119119// Don't lint unnamed constants
120120const _: ( ) = ( ) ;
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.
Original file line number Diff line number Diff line change @@ -88,5 +88,14 @@ error: missing documentation for a function
8888LL | 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
You can’t perform that action at this time.
0 commit comments