@@ -153,11 +153,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
153153 fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
154154 let headers = check_attrs ( cx, & self . valid_idents , & item. attrs ) ;
155155 match item. kind {
156- hir:: ItemKind :: Fn ( ref sig, .. ) => {
156+ hir:: ItemKind :: Fn ( ref sig, _ , body_id ) => {
157157 if !( is_entrypoint_fn ( cx, cx. tcx . hir ( ) . local_def_id ( item. hir_id ) )
158158 || in_external_macro ( cx. tcx . sess , item. span ) )
159159 {
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 ) ) ;
161161 }
162162 } ,
163163 hir:: ItemKind :: Impl {
@@ -180,7 +180,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
180180 let headers = check_attrs ( cx, & self . valid_idents , & item. attrs ) ;
181181 if let hir:: TraitItemKind :: Method ( ref sig, ..) = item. kind {
182182 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 ) ;
184184 }
185185 }
186186 }
@@ -190,8 +190,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
190190 if self . in_trait_impl || in_external_macro ( cx. tcx . sess , item. span ) {
191191 return ;
192192 }
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 ) ) ;
195195 }
196196 }
197197}
@@ -202,6 +202,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
202202 span : impl Into < MultiSpan > + Copy ,
203203 sig : & hir:: FnSig < ' _ > ,
204204 headers : DocHeaders ,
205+ body_id : Option < hir:: BodyId > ,
205206) {
206207 if !cx. access_levels . is_exported ( hir_id) {
207208 return ; // Private functions do not require doc comments
@@ -222,24 +223,24 @@ fn lint_for_missing_headers<'a, 'tcx>(
222223 span,
223224 "docs for function returning `Result` missing `# Errors` section" ,
224225 ) ;
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 ) ;
227228 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+ ) ;
243244 }
244245 }
245246 }
0 commit comments