Skip to content

Commit 89c0d4f

Browse files
Apply missing_docs lint on tuple fields as well
1 parent 1c858ba commit 89c0d4f

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,17 @@ pub struct MissingDoc {
488488

489489
/// Private traits or trait items that leaked through. Don't check their methods.
490490
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,
491502
}
492503

493504
impl_lint_pass!(MissingDoc => [MISSING_DOCS]);
@@ -518,7 +529,11 @@ fn has_doc(attr: &ast::Attribute) -> bool {
518529

519530
impl MissingDoc {
520531
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+
}
522537
}
523538

524539
fn doc_hidden(&self) -> bool {
@@ -616,6 +631,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
616631
}
617632
return;
618633
}
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+
}
619640

620641
hir::ItemKind::TyAlias(..)
621642
| hir::ItemKind::Fn(..)
@@ -661,14 +682,23 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
661682
}
662683

663684
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;
667688
}
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")
668691
}
669692

670693
fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) {
671694
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+
}
672702
}
673703
}
674704

0 commit comments

Comments
 (0)