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

check missing docs for reexported macros as well #56407

Merged
Merged
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
2 changes: 2 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
#![feature(reverse_bits)]
#![feature(non_exhaustive)]
#![feature(structural_match)]
#![feature(abi_unadjusted)]
#![cfg_attr(not(stage0), feature(adx_target_feature))]

#[prelude_import]
#[allow(unused)]
Expand Down
49 changes: 29 additions & 20 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ pub struct MissingDoc {
private_traits: FxHashSet<ast::NodeId>,
}

fn has_doc(attr: &ast::Attribute) -> bool {
if !attr.check_name("doc") {
return false;
}

if attr.is_value_str() {
return true;
}

if let Some(list) = attr.meta_item_list() {
for meta in list {
if meta.check_name("include") || meta.check_name("hidden") {
return true;
}
}
}

false
}

impl MissingDoc {
pub fn new() -> MissingDoc {
MissingDoc {
Expand Down Expand Up @@ -335,26 +355,6 @@ impl MissingDoc {
}
}

fn has_doc(attr: &ast::Attribute) -> bool {
if !attr.check_name("doc") {
return false;
}

if attr.is_value_str() {
return true;
}

if let Some(list) = attr.meta_item_list() {
for meta in list {
if meta.check_name("include") {
return true;
}
}
}

false
}

let has_doc = attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.span_lint(MISSING_DOCS,
Expand Down Expand Up @@ -389,6 +389,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {

fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");

for macro_def in &krate.exported_macros {
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.span_lint(MISSING_DOCS,
cx.tcx.sess.source_map().def_span(macro_def.span),
"missing documentation for macro");
}
}
}

fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
Expand Down
1 change: 1 addition & 0 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ macro_rules! dbg {
}
}

/// A macro to await on an async call.
#[macro_export]
#[unstable(feature = "await_macro", issue = "50547")]
#[allow_internal_unstable]
Expand Down
2 changes: 1 addition & 1 deletion src/stdsimd
13 changes: 13 additions & 0 deletions src/test/rustdoc-ui/deny-missing-docs-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
Copy link
Member

@varkor varkor Dec 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: copyright is no longer needed.

// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(missing_docs)] //~ ERROR

pub struct Foo; //~ ERROR
22 changes: 22 additions & 0 deletions src/test/rustdoc-ui/deny-missing-docs-crate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: missing documentation for crate
--> $DIR/deny-missing-docs-crate.rs:11:1
|
LL | / #![deny(missing_docs)] //~ ERROR
LL | |
LL | | pub struct Foo; //~ ERROR
| |_______________^
|
note: lint level defined here
--> $DIR/deny-missing-docs-crate.rs:11:9
|
LL | #![deny(missing_docs)] //~ ERROR
| ^^^^^^^^^^^^

error: missing documentation for a struct
--> $DIR/deny-missing-docs-crate.rs:13:1
|
LL | pub struct Foo; //~ ERROR
| ^^^^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc

18 changes: 18 additions & 0 deletions src/test/rustdoc-ui/deny-missing-docs-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! foo

#![deny(missing_docs)]

#[macro_export]
macro_rules! foo { //~ ERROR
() => {}
}
14 changes: 14 additions & 0 deletions src/test/rustdoc-ui/deny-missing-docs-macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: missing documentation for macro
--> $DIR/deny-missing-docs-macro.rs:16:1
|
LL | macro_rules! foo { //~ ERROR
| ^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/deny-missing-docs-macro.rs:13:9
|
LL | #![deny(missing_docs)]
| ^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc