Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use missing_docs lint on tuple fields as well #88688

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@ pub struct MissingDoc {

/// Private traits or trait items that leaked through. Don't check their methods.
private_traits: FxHashSet<hir::HirId>,

/// 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]);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(..)
Expand Down Expand Up @@ -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;
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:`.
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc-ui/missing-doc-tuple-variant.rs
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 20 additions & 0 deletions src/test/rustdoc-ui/missing-doc-tuple-variant.stderr
Original file line number Diff line number Diff line change
@@ -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