@@ -153,11 +153,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
153
153
fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
154
154
let headers = check_attrs ( cx, & self . valid_idents , & item. attrs ) ;
155
155
match item. kind {
156
- hir:: ItemKind :: Fn ( ref sig, .. ) => {
156
+ hir:: ItemKind :: Fn ( ref sig, _ , body_id ) => {
157
157
if !( is_entrypoint_fn ( cx, cx. tcx . hir ( ) . local_def_id ( item. hir_id ) )
158
158
|| in_external_macro ( cx. tcx . sess , item. span ) )
159
159
{
160
- lint_for_missing_headers ( cx, item. hir_id , item. span , sig, headers) ;
160
+ lint_for_missing_headers ( cx, item. hir_id , item. span , sig, headers, Some ( body_id ) ) ;
161
161
}
162
162
} ,
163
163
hir:: ItemKind :: Impl {
@@ -180,7 +180,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
180
180
let headers = check_attrs ( cx, & self . valid_idents , & item. attrs ) ;
181
181
if let hir:: TraitItemKind :: Method ( ref sig, ..) = item. kind {
182
182
if !in_external_macro ( cx. tcx . sess , item. span ) {
183
- lint_for_missing_headers ( cx, item. hir_id , item. span , sig, headers) ;
183
+ lint_for_missing_headers ( cx, item. hir_id , item. span , sig, headers, None ) ;
184
184
}
185
185
}
186
186
}
@@ -190,8 +190,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
190
190
if self . in_trait_impl || in_external_macro ( cx. tcx . sess , item. span ) {
191
191
return ;
192
192
}
193
- if let hir:: ImplItemKind :: Method ( ref sig, .. ) = item. kind {
194
- lint_for_missing_headers ( cx, item. hir_id , item. span , sig, headers) ;
193
+ if let hir:: ImplItemKind :: Method ( ref sig, body_id ) = item. kind {
194
+ lint_for_missing_headers ( cx, item. hir_id , item. span , sig, headers, Some ( body_id ) ) ;
195
195
}
196
196
}
197
197
}
@@ -202,6 +202,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
202
202
span : impl Into < MultiSpan > + Copy ,
203
203
sig : & hir:: FnSig < ' _ > ,
204
204
headers : DocHeaders ,
205
+ body_id : Option < hir:: BodyId > ,
205
206
) {
206
207
if !cx. access_levels . is_exported ( hir_id) {
207
208
return ; // Private functions do not require doc comments
@@ -222,24 +223,24 @@ fn lint_for_missing_headers<'a, 'tcx>(
222
223
span,
223
224
"docs for function returning `Result` missing `# Errors` section" ,
224
225
) ;
225
- } else {
226
- let def_id = cx. tcx . hir ( ) . local_def_id ( hir_id ) ;
226
+ } else if let ( Some ( body_id ) , Some ( future ) ) = ( body_id , get_trait_def_id ( cx , & paths :: FUTURE ) ) {
227
+ let def_id = cx. tcx . hir ( ) . body_owner_def_id ( body_id ) ;
227
228
let mir = cx. tcx . optimized_mir ( def_id) ;
228
- if let Some ( future ) = get_trait_def_id ( cx , & paths :: FUTURE ) {
229
- if implements_trait ( cx , mir . return_ty ( ) , future , & [ ] ) {
230
- use TyKind :: * ;
231
-
232
- if let Opaque ( _ , subs ) = mir . return_ty ( ) . kind {
233
- if let Some ( ty ) = subs . types ( ) . next ( ) {
234
- if let Generator ( _ , subs , _ ) = ty . kind {
235
- if match_type ( cx , subs. as_generator ( ) . return_ty ( def_id , cx . tcx ) , & paths :: RESULT ) {
236
- span_lint (
237
- cx ,
238
- MISSING_ERRORS_DOC ,
239
- span ,
240
- "docs for function returning `Result` missing `# Errors` section" ,
241
- ) ;
242
- }
229
+ let ret_ty = mir . return_ty ( ) ;
230
+
231
+ if implements_trait ( cx , ret_ty , future , & [ ] ) {
232
+ use TyKind :: * ;
233
+
234
+ if let Opaque ( _ , subs ) = ret_ty . kind {
235
+ if let Some ( ty ) = subs . types ( ) . next ( ) {
236
+ if let Generator ( _ , subs, _ ) = ty . kind {
237
+ if match_type ( cx , subs . as_generator ( ) . return_ty ( def_id , cx . tcx ) , & paths :: RESULT ) {
238
+ span_lint (
239
+ cx ,
240
+ MISSING_ERRORS_DOC ,
241
+ span ,
242
+ "docs for function returning `Result` missing `# Errors` section" ,
243
+ ) ;
243
244
}
244
245
}
245
246
}
0 commit comments