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;
12
12
use clippy_utils:: source:: SpanRangeExt ;
13
13
use rustc_ast:: ast:: { self , MetaItem , MetaItemKind } ;
14
14
use rustc_hir as hir;
15
+ use rustc_hir:: def:: DefKind ;
15
16
use rustc_hir:: def_id:: LocalDefId ;
16
17
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
17
18
use rustc_middle:: ty:: Visibility ;
@@ -111,6 +112,21 @@ impl MissingDoc {
111
112
return ;
112
113
}
113
114
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
+
114
130
let has_doc = attrs
115
131
. iter ( )
116
132
. 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;);
119
119
// Don't lint unnamed constants
120
120
const _: ( ) = ( ) ;
121
121
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
+
122
127
// issue #12197
123
128
// Undocumented field originated inside of spanned proc-macro attribute
124
129
/// Some dox for struct.
Original file line number Diff line number Diff line change @@ -88,5 +88,14 @@ error: missing documentation for a function
88
88
LL | fn also_undocumented2() {}
89
89
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
90
90
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
92
101
You can’t perform that action at this time.
0 commit comments