@@ -349,6 +349,7 @@ impl MissingDoc {
349
349
id : Option < hir:: HirId > ,
350
350
attrs : & [ ast:: Attribute ] ,
351
351
sp : Span ,
352
+ article : & ' static str ,
352
353
desc : & ' static str ,
353
354
) {
354
355
// If we're building a test harness, then warning about
@@ -374,7 +375,7 @@ impl MissingDoc {
374
375
let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
375
376
if !has_doc {
376
377
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 ( )
378
379
} ) ;
379
380
}
380
381
}
@@ -398,7 +399,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
398
399
}
399
400
400
401
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") ;
402
403
403
404
for macro_def in krate. exported_macros {
404
405
let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
@@ -413,12 +414,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
413
414
}
414
415
415
416
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 {
422
418
hir:: ItemKind :: Trait ( .., trait_item_refs) => {
423
419
// Issue #11592: traits are always considered exported, even when private.
424
420
if let hir:: VisibilityKind :: Inherited = it. vis . node {
@@ -428,51 +424,55 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
428
424
}
429
425
return ;
430
426
}
431
- "a trait"
432
427
}
433
- hir:: ItemKind :: TyAlias ( ..) => "a type alias" ,
434
428
hir:: ItemKind :: Impl { of_trait : Some ( ref trait_ref) , items, .. } => {
435
429
// If the trait is private, add the impl items to `private_traits` so they don't get
436
430
// reported for missing docs.
437
431
let real_trait = trait_ref. path . res . def_id ( ) ;
438
432
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 ) ;
445
437
}
446
438
}
447
- _ => { }
448
439
}
449
440
}
450
441
return ;
451
442
}
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
+
454
453
_ => return ,
455
454
} ;
456
455
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) ;
458
460
}
459
461
460
462
fn check_trait_item ( & mut self , cx : & LateContext < ' _ , ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
461
463
if self . private_traits . contains ( & trait_item. hir_id ) {
462
464
return ;
463
465
}
464
466
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) ;
470
469
471
470
self . check_missing_docs_attrs (
472
471
cx,
473
472
Some ( trait_item. hir_id ) ,
474
473
& trait_item. attrs ,
475
474
trait_item. span ,
475
+ article,
476
476
desc,
477
477
) ;
478
478
}
@@ -483,29 +483,33 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
483
483
return ;
484
484
}
485
485
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) ;
492
488
self . check_missing_docs_attrs (
493
489
cx,
494
490
Some ( impl_item. hir_id ) ,
495
491
& impl_item. attrs ,
496
492
impl_item. span ,
493
+ article,
497
494
desc,
498
495
) ;
499
496
}
500
497
501
498
fn check_struct_field ( & mut self , cx : & LateContext < ' _ , ' _ > , sf : & hir:: StructField < ' _ > ) {
502
499
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
+ )
504
508
}
505
509
}
506
510
507
511
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") ;
509
513
}
510
514
}
511
515
0 commit comments