@@ -488,6 +488,17 @@ pub struct MissingDoc {
488
488
489
489
/// Private traits or trait items that leaked through. Don't check their methods.
490
490
private_traits : FxHashSet < hir:: HirId > ,
491
+
492
+ /// In case we have:
493
+ ///
494
+ /// ```
495
+ /// enum Foo { Bar(u32) }
496
+ /// // or:
497
+ /// struct Bar(u32);
498
+ /// ```
499
+ ///
500
+ /// No need to require documentation on the unique field.
501
+ is_ignorable : bool ,
491
502
}
492
503
493
504
impl_lint_pass ! ( MissingDoc => [ MISSING_DOCS ] ) ;
@@ -518,7 +529,11 @@ fn has_doc(attr: &ast::Attribute) -> bool {
518
529
519
530
impl MissingDoc {
520
531
pub fn new ( ) -> MissingDoc {
521
- MissingDoc { doc_hidden_stack : vec ! [ false ] , private_traits : FxHashSet :: default ( ) }
532
+ MissingDoc {
533
+ doc_hidden_stack : vec ! [ false ] ,
534
+ private_traits : FxHashSet :: default ( ) ,
535
+ is_ignorable : false ,
536
+ }
522
537
}
523
538
524
539
fn doc_hidden ( & self ) -> bool {
@@ -616,6 +631,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
616
631
}
617
632
return ;
618
633
}
634
+ hir:: ItemKind :: Struct ( hir:: VariantData :: Tuple ( fields, _) , _) => {
635
+ if fields. len ( ) < 2 {
636
+ // No need to check if there is missing documentation on the field.
637
+ self . is_ignorable = true ;
638
+ }
639
+ }
619
640
620
641
hir:: ItemKind :: TyAlias ( ..)
621
642
| hir:: ItemKind :: Fn ( ..)
@@ -661,14 +682,23 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
661
682
}
662
683
663
684
fn check_field_def ( & mut self , cx : & LateContext < ' _ > , sf : & hir:: FieldDef < ' _ > ) {
664
- if !sf . is_positional ( ) {
665
- let def_id = cx . tcx . hir ( ) . local_def_id ( sf . hir_id ) ;
666
- self . check_missing_docs_attrs ( cx , def_id , sf . span , "a" , "struct field" )
685
+ if self . is_ignorable {
686
+ self . is_ignorable = false ;
687
+ return ;
667
688
}
689
+ let def_id = cx. tcx . hir ( ) . local_def_id ( sf. hir_id ) ;
690
+ self . check_missing_docs_attrs ( cx, def_id, sf. span , "a" , "struct field" )
668
691
}
669
692
670
693
fn check_variant ( & mut self , cx : & LateContext < ' _ > , v : & hir:: Variant < ' _ > ) {
671
694
self . check_missing_docs_attrs ( cx, cx. tcx . hir ( ) . local_def_id ( v. id ) , v. span , "a" , "variant" ) ;
695
+ if let hir:: VariantData :: Tuple ( fields, _) = v. data {
696
+ if fields. len ( ) < 2 {
697
+ // No need to check if there is missing documentation on the variant field.
698
+ self . is_ignorable = true ;
699
+ return ;
700
+ }
701
+ }
672
702
}
673
703
}
674
704
0 commit comments