Emit some additional `unused_doc_comments` lints outside of the main pass

This commit is contained in:
Vadim Petrochenkov 2020-02-15 15:29:45 +03:00
parent bcd7e2b38b
commit 1bd6b98220
5 changed files with 44 additions and 16 deletions

View File

@ -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");
}
}
}
}

View File

@ -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<'_>,

View File

@ -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]);

View File

@ -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

View File

@ -1,3 +1,21 @@
error: yep, it's unused
--> $DIR/useless-comment.rs:9:1
|
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
|
@ -5,12 +23,6 @@ LL | /// a
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let x = 12;
| ----------- rustdoc does not generate documentation for statements
|
note: the lint level is defined here
--> $DIR/useless-comment.rs:3:9
|
LL | #![deny(unused_doc_comments)]
| ^^^^^^^^^^^^^^^^^^^
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