@@ -349,6 +349,7 @@ impl MissingDoc {
349349 id : Option < hir:: HirId > ,
350350 attrs : & [ ast:: Attribute ] ,
351351 sp : Span ,
352+ article : & ' static str ,
352353 desc : & ' static str ,
353354 ) {
354355 // If we're building a test harness, then warning about
@@ -374,7 +375,7 @@ impl MissingDoc {
374375 let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
375376 if !has_doc {
376377 cx. struct_span_lint ( MISSING_DOCS , cx. tcx . sess . source_map ( ) . def_span ( sp) , |lint| {
377- lint. build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( )
378+ lint. build ( & format ! ( "missing documentation for {} {}" , article , desc) ) . emit ( )
378379 } ) ;
379380 }
380381 }
@@ -398,7 +399,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
398399 }
399400
400401 fn check_crate ( & mut self , cx : & LateContext < ' _ , ' _ > , krate : & hir:: Crate < ' _ > ) {
401- self . check_missing_docs_attrs ( cx, None , & krate. item . attrs , krate. item . span , "crate" ) ;
402+ self . check_missing_docs_attrs ( cx, None , & krate. item . attrs , krate. item . span , "the" , " crate") ;
402403
403404 for macro_def in krate. exported_macros {
404405 let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
@@ -413,12 +414,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
413414 }
414415
415416 fn check_item ( & mut self , cx : & LateContext < ' _ , ' _ > , it : & hir:: Item < ' _ > ) {
416- let desc = match it. kind {
417- hir:: ItemKind :: Fn ( ..) => "a function" ,
418- hir:: ItemKind :: Mod ( ..) => "a module" ,
419- hir:: ItemKind :: Enum ( ..) => "an enum" ,
420- hir:: ItemKind :: Struct ( ..) => "a struct" ,
421- hir:: ItemKind :: Union ( ..) => "a union" ,
417+ match it. kind {
422418 hir:: ItemKind :: Trait ( .., trait_item_refs) => {
423419 // Issue #11592: traits are always considered exported, even when private.
424420 if let hir:: VisibilityKind :: Inherited = it. vis . node {
@@ -428,51 +424,55 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
428424 }
429425 return ;
430426 }
431- "a trait"
432427 }
433- hir:: ItemKind :: TyAlias ( ..) => "a type alias" ,
434428 hir:: ItemKind :: Impl { of_trait : Some ( ref trait_ref) , items, .. } => {
435429 // If the trait is private, add the impl items to `private_traits` so they don't get
436430 // reported for missing docs.
437431 let real_trait = trait_ref. path . res . def_id ( ) ;
438432 if let Some ( hir_id) = cx. tcx . hir ( ) . as_local_hir_id ( real_trait) {
439- match cx. tcx . hir ( ) . find ( hir_id) {
440- Some ( Node :: Item ( item) ) => {
441- if let hir:: VisibilityKind :: Inherited = item. vis . node {
442- for impl_item_ref in items {
443- self . private_traits . insert ( impl_item_ref. id . hir_id ) ;
444- }
433+ if let Some ( Node :: Item ( item) ) = cx. tcx . hir ( ) . find ( hir_id) {
434+ if let hir:: VisibilityKind :: Inherited = item. vis . node {
435+ for impl_item_ref in items {
436+ self . private_traits . insert ( impl_item_ref. id . hir_id ) ;
445437 }
446438 }
447- _ => { }
448439 }
449440 }
450441 return ;
451442 }
452- hir:: ItemKind :: Const ( ..) => "a constant" ,
453- hir:: ItemKind :: Static ( ..) => "a static" ,
443+
444+ hir:: ItemKind :: TyAlias ( ..)
445+ | hir:: ItemKind :: Fn ( ..)
446+ | hir:: ItemKind :: Mod ( ..)
447+ | hir:: ItemKind :: Enum ( ..)
448+ | hir:: ItemKind :: Struct ( ..)
449+ | hir:: ItemKind :: Union ( ..)
450+ | hir:: ItemKind :: Const ( ..)
451+ | hir:: ItemKind :: Static ( ..) => { }
452+
454453 _ => return ,
455454 } ;
456455
457- self . check_missing_docs_attrs ( cx, Some ( it. hir_id ) , & it. attrs , it. span , desc) ;
456+ let def_id = cx. tcx . hir ( ) . local_def_id ( it. hir_id ) ;
457+ let ( article, desc) = cx. tcx . article_and_description ( def_id) ;
458+
459+ self . check_missing_docs_attrs ( cx, Some ( it. hir_id ) , & it. attrs , it. span , article, desc) ;
458460 }
459461
460462 fn check_trait_item ( & mut self , cx : & LateContext < ' _ , ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
461463 if self . private_traits . contains ( & trait_item. hir_id ) {
462464 return ;
463465 }
464466
465- let desc = match trait_item. kind {
466- hir:: TraitItemKind :: Const ( ..) => "an associated constant" ,
467- hir:: TraitItemKind :: Fn ( ..) => "a trait method" ,
468- hir:: TraitItemKind :: Type ( ..) => "an associated type" ,
469- } ;
467+ let def_id = cx. tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ;
468+ let ( article, desc) = cx. tcx . article_and_description ( def_id) ;
470469
471470 self . check_missing_docs_attrs (
472471 cx,
473472 Some ( trait_item. hir_id ) ,
474473 & trait_item. attrs ,
475474 trait_item. span ,
475+ article,
476476 desc,
477477 ) ;
478478 }
@@ -483,29 +483,33 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
483483 return ;
484484 }
485485
486- let desc = match impl_item. kind {
487- hir:: ImplItemKind :: Const ( ..) => "an associated constant" ,
488- hir:: ImplItemKind :: Fn ( ..) => "a method" ,
489- hir:: ImplItemKind :: TyAlias ( _) => "an associated type" ,
490- hir:: ImplItemKind :: OpaqueTy ( _) => "an associated `impl Trait` type" ,
491- } ;
486+ let def_id = cx. tcx . hir ( ) . local_def_id ( impl_item. hir_id ) ;
487+ let ( article, desc) = cx. tcx . article_and_description ( def_id) ;
492488 self . check_missing_docs_attrs (
493489 cx,
494490 Some ( impl_item. hir_id ) ,
495491 & impl_item. attrs ,
496492 impl_item. span ,
493+ article,
497494 desc,
498495 ) ;
499496 }
500497
501498 fn check_struct_field ( & mut self , cx : & LateContext < ' _ , ' _ > , sf : & hir:: StructField < ' _ > ) {
502499 if !sf. is_positional ( ) {
503- self . check_missing_docs_attrs ( cx, Some ( sf. hir_id ) , & sf. attrs , sf. span , "a struct field" )
500+ self . check_missing_docs_attrs (
501+ cx,
502+ Some ( sf. hir_id ) ,
503+ & sf. attrs ,
504+ sf. span ,
505+ "a" ,
506+ "struct field" ,
507+ )
504508 }
505509 }
506510
507511 fn check_variant ( & mut self , cx : & LateContext < ' _ , ' _ > , v : & hir:: Variant < ' _ > ) {
508- self . check_missing_docs_attrs ( cx, Some ( v. id ) , & v. attrs , v. span , "a variant" ) ;
512+ self . check_missing_docs_attrs ( cx, Some ( v. id ) , & v. attrs , v. span , "a" , " variant") ;
509513 }
510514}
511515
0 commit comments