Skip to content

Commit 1bd6b98

Browse files
committed
Emit some additional unused_doc_comments lints outside of the main pass
1 parent bcd7e2b commit 1bd6b98

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

src/librustc_expand/expand.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_parse::configure;
1414
use rustc_parse::parser::Parser;
1515
use rustc_parse::validate_attr;
1616
use rustc_parse::DirectoryOwnership;
17+
use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS;
1718
use rustc_session::parse::{feature_err, ParseSess};
1819
use rustc_span::source_map::respan;
1920
use rustc_span::symbol::{sym, Symbol};
@@ -1090,6 +1091,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10901091
.note("this may become a hard error in a future release")
10911092
.emit();
10921093
}
1094+
1095+
if attr.doc_str().is_some() {
1096+
self.cx.parse_sess.buffer_lint(&UNUSED_DOC_COMMENTS, attr.span, ast::CRATE_NODE_ID, "yep, it's unused");
1097+
}
10931098
}
10941099
}
10951100
}

src/librustc_lint/builtin.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,18 @@ impl EarlyLintPass for DeprecatedAttr {
738738
}
739739
}
740740

741-
declare_lint! {
742-
pub UNUSED_DOC_COMMENTS,
743-
Warn,
744-
"detects doc comments that aren't used by rustdoc"
741+
trait UnusedDocCommentExt {
742+
fn warn_if_doc(
743+
&self,
744+
cx: &EarlyContext<'_>,
745+
node_span: Span,
746+
node_kind: &str,
747+
is_macro_expansion: bool,
748+
attrs: &[ast::Attribute],
749+
);
745750
}
746751

747-
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
748-
749-
impl UnusedDocComment {
752+
impl UnusedDocCommentExt for UnusedDocComment {
750753
fn warn_if_doc(
751754
&self,
752755
cx: &EarlyContext<'_>,

src/librustc_session/lint/builtin.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,11 @@ declare_lint_pass! {
557557
INLINE_NO_SANITIZE,
558558
]
559559
}
560+
561+
declare_lint! {
562+
pub UNUSED_DOC_COMMENTS,
563+
Warn,
564+
"detects doc comments that aren't used by rustdoc"
565+
}
566+
567+
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);

src/test/ui/useless-comment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ macro_rules! mac {
66
() => {}
77
}
88

9-
/// foo //FIXME ERROR unused doc comment
9+
/// foo //~ ERROR yep, it's unused
1010
mac!();
1111

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

32-
/// bar //FIXME ERROR unused doc comment
32+
/// bar //~ ERROR yep, it's unused
3333
mac!();
3434

3535
let x = /** comment */ 47; //~ ERROR unused doc comment

src/test/ui/useless-comment.stderr

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
error: unused doc comment
2-
--> $DIR/useless-comment.rs:13:5
1+
error: yep, it's unused
2+
--> $DIR/useless-comment.rs:9:1
33
|
4-
LL | /// a
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
LL | let x = 12;
7-
| ----------- rustdoc does not generate documentation for statements
4+
LL | /// foo
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
|
97
note: the lint level is defined here
108
--> $DIR/useless-comment.rs:3:9
119
|
1210
LL | #![deny(unused_doc_comments)]
1311
| ^^^^^^^^^^^^^^^^^^^
1412

13+
error: yep, it's unused
14+
--> $DIR/useless-comment.rs:32:5
15+
|
16+
LL | /// bar
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: unused doc comment
20+
--> $DIR/useless-comment.rs:13:5
21+
|
22+
LL | /// a
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
LL | let x = 12;
25+
| ----------- rustdoc does not generate documentation for statements
26+
1527
error: unused doc comment
1628
--> $DIR/useless-comment.rs:16:5
1729
|
@@ -75,5 +87,5 @@ LL | |
7587
LL | | }
7688
| |_____- rustdoc does not generate documentation for expressions
7789

78-
error: aborting due to 8 previous errors
90+
error: aborting due to 10 previous errors
7991

0 commit comments

Comments
 (0)