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

Split non macro portion of unused_doc_comment from macro part into two passes/lints #69084

Merged
merged 7 commits into from
Feb 23, 2020
Merged
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ use rustc_parse::configure;
use rustc_parse::parser::Parser;
use rustc_parse::validate_attr;
use rustc_parse::DirectoryOwnership;
use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS;
use rustc_session::parse::{feature_err, ParseSess};
use rustc_span::source_map::respan;
use rustc_span::symbol::{sym, Symbol};
@@ -1090,6 +1091,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
.note("this may become a hard error in a future release")
.emit();
}

if attr.doc_str().is_some() {
self.cx.parse_sess.buffer_lint(&UNUSED_DOC_COMMENTS, attr.span, ast::CRATE_NODE_ID, "yep, it's unused");
}
}
}
}
17 changes: 10 additions & 7 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -738,15 +738,18 @@ impl EarlyLintPass for DeprecatedAttr {
}
}

declare_lint! {
pub UNUSED_DOC_COMMENTS,
Warn,
"detects doc comments that aren't used by rustdoc"
trait UnusedDocCommentExt {
fn warn_if_doc(
&self,
cx: &EarlyContext<'_>,
node_span: Span,
node_kind: &str,
is_macro_expansion: bool,
attrs: &[ast::Attribute],
);
}

declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);

impl UnusedDocComment {
impl UnusedDocCommentExt for UnusedDocComment {
fn warn_if_doc(
&self,
cx: &EarlyContext<'_>,
8 changes: 8 additions & 0 deletions src/librustc_session/lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -557,3 +557,11 @@ declare_lint_pass! {
INLINE_NO_SANITIZE,
]
}

declare_lint! {
pub UNUSED_DOC_COMMENTS,
Warn,
"detects doc comments that aren't used by rustdoc"
}

declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
4 changes: 2 additions & 2 deletions src/test/ui/useless-comment.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ macro_rules! mac {
() => {}
}

/// foo //FIXME ERROR unused doc comment
/// foo //~ ERROR yep, it's unused
mac!();

fn foo() {
@@ -29,7 +29,7 @@ fn foo() {
#[doc = "bar"] //~ ERROR unused doc comment
3;

/// bar //FIXME ERROR unused doc comment
/// bar //~ ERROR yep, it's unused
mac!();

let x = /** comment */ 47; //~ ERROR unused doc comment
26 changes: 19 additions & 7 deletions src/test/ui/useless-comment.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
error: unused doc comment
--> $DIR/useless-comment.rs:13:5
error: yep, it's unused
--> $DIR/useless-comment.rs:9:1
|
LL | /// a
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let x = 12;
| ----------- rustdoc does not generate documentation for statements
LL | /// foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/useless-comment.rs:3:9
|
LL | #![deny(unused_doc_comments)]
| ^^^^^^^^^^^^^^^^^^^

error: yep, it's unused
--> $DIR/useless-comment.rs:32:5
|
LL | /// bar
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unused doc comment
--> $DIR/useless-comment.rs:13:5
|
LL | /// a
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let x = 12;
| ----------- rustdoc does not generate documentation for statements

error: unused doc comment
--> $DIR/useless-comment.rs:16:5
|
@@ -75,5 +87,5 @@ LL | |
LL | | }
| |_____- rustdoc does not generate documentation for expressions

error: aborting due to 8 previous errors
error: aborting due to 10 previous errors