diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 2850e7a6b44e9..357b57141f649 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -488,6 +488,17 @@ pub struct MissingDoc { /// Private traits or trait items that leaked through. Don't check their methods. private_traits: FxHashSet, + + /// In case we have: + /// + /// ``` + /// enum Foo { Bar(u32) } + /// // or: + /// struct Bar(u32); + /// ``` + /// + /// No need to require documentation on the unique field. + is_ignorable: bool, } impl_lint_pass!(MissingDoc => [MISSING_DOCS]); @@ -518,7 +529,11 @@ fn has_doc(attr: &ast::Attribute) -> bool { impl MissingDoc { pub fn new() -> MissingDoc { - MissingDoc { doc_hidden_stack: vec![false], private_traits: FxHashSet::default() } + MissingDoc { + doc_hidden_stack: vec![false], + private_traits: FxHashSet::default(), + is_ignorable: false, + } } fn doc_hidden(&self) -> bool { @@ -616,6 +631,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } return; } + hir::ItemKind::Struct(hir::VariantData::Tuple(fields, _), _) => { + if fields.len() < 2 { + // No need to check if there is missing documentation on the field. + self.is_ignorable = true; + } + } hir::ItemKind::TyAlias(..) | hir::ItemKind::Fn(..) @@ -661,14 +682,23 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) { - if !sf.is_positional() { - let def_id = cx.tcx.hir().local_def_id(sf.hir_id); - self.check_missing_docs_attrs(cx, def_id, sf.span, "a", "struct field") + if self.is_ignorable { + self.is_ignorable = false; + return; } + let def_id = cx.tcx.hir().local_def_id(sf.hir_id); + self.check_missing_docs_attrs(cx, def_id, sf.span, "a", "struct field") } fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) { self.check_missing_docs_attrs(cx, cx.tcx.hir().local_def_id(v.id), v.span, "a", "variant"); + if let hir::VariantData::Tuple(fields, _) = v.data { + if fields.len() < 2 { + // No need to check if there is missing documentation on the variant field. + self.is_ignorable = true; + return; + } + } } } diff --git a/library/core/src/str/pattern.rs b/library/core/src/str/pattern.rs index 55ac1aa765c1f..7aee5c78e2a74 100644 --- a/library/core/src/str/pattern.rs +++ b/library/core/src/str/pattern.rs @@ -161,13 +161,13 @@ pub trait Pattern<'a>: Sized { pub enum SearchStep { /// Expresses that a match of the pattern has been found at /// `haystack[a..b]`. - Match(usize, usize), + Match(#[allow(missing_docs)] usize, #[allow(missing_docs)] usize), /// Expresses that `haystack[a..b]` has been rejected as a possible match /// of the pattern. /// /// Note that there might be more than one `Reject` between two `Match`es, /// there is no requirement for them to be combined into one. - Reject(usize, usize), + Reject(#[allow(missing_docs)] usize, #[allow(missing_docs)] usize), /// Expresses that every byte of the haystack has been visited, ending /// the iteration. Done, diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 2a9c361c18afc..7464666abe306 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -147,8 +147,12 @@ pub enum Prefix<'a> { /// server's hostname and a share name. #[stable(feature = "rust1", since = "1.0.0")] VerbatimUNC( - #[stable(feature = "rust1", since = "1.0.0")] &'a OsStr, - #[stable(feature = "rust1", since = "1.0.0")] &'a OsStr, + #[stable(feature = "rust1", since = "1.0.0")] + #[allow(missing_docs)] + &'a OsStr, + #[stable(feature = "rust1", since = "1.0.0")] + #[allow(missing_docs)] + &'a OsStr, ), /// Verbatim disk prefix, e.g., `\\?\C:`. @@ -171,8 +175,12 @@ pub enum Prefix<'a> { /// UNC prefixes consist of the server's hostname and a share name. #[stable(feature = "rust1", since = "1.0.0")] UNC( - #[stable(feature = "rust1", since = "1.0.0")] &'a OsStr, - #[stable(feature = "rust1", since = "1.0.0")] &'a OsStr, + #[stable(feature = "rust1", since = "1.0.0")] + #[allow(missing_docs)] + &'a OsStr, + #[stable(feature = "rust1", since = "1.0.0")] + #[allow(missing_docs)] + &'a OsStr, ), /// Prefix `C:` for the given disk drive. diff --git a/src/test/rustdoc-ui/missing-doc-tuple-variant.rs b/src/test/rustdoc-ui/missing-doc-tuple-variant.rs new file mode 100644 index 0000000000000..322c5053a5827 --- /dev/null +++ b/src/test/rustdoc-ui/missing-doc-tuple-variant.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z unstable-options --check + +#![deny(missing_docs)] + +//! crate level doc + +/// Enum doc. +pub enum Foo { + /// Variant doc. + Foo(String), + /// Variant Doc. + Bar(String, u32), + //~^ ERROR + //~^^ ERROR +} diff --git a/src/test/rustdoc-ui/missing-doc-tuple-variant.stderr b/src/test/rustdoc-ui/missing-doc-tuple-variant.stderr new file mode 100644 index 0000000000000..49768627dd000 --- /dev/null +++ b/src/test/rustdoc-ui/missing-doc-tuple-variant.stderr @@ -0,0 +1,20 @@ +error: missing documentation for a struct field + --> $DIR/missing-doc-tuple-variant.rs:12:9 + | +LL | Bar(String, u32), + | ^^^^^^ + | +note: the lint level is defined here + --> $DIR/missing-doc-tuple-variant.rs:3:9 + | +LL | #![deny(missing_docs)] + | ^^^^^^^^^^^^ + +error: missing documentation for a struct field + --> $DIR/missing-doc-tuple-variant.rs:12:17 + | +LL | Bar(String, u32), + | ^^^ + +error: aborting due to 2 previous errors +