Skip to content

Commit e967d0c

Browse files
committed
rustdoc: Also run lint unused_doc_comments
1 parent 4f8ea98 commit e967d0c

5 files changed

Lines changed: 56 additions & 5 deletions

File tree

src/librustdoc/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub(crate) fn create_config(
235235
// it's unclear whether these should be part of rustdoc directly (#77364)
236236
rustc_lint::builtin::MISSING_DOCS.name.to_string(),
237237
rustc_lint::builtin::INVALID_DOC_ATTRIBUTES.name.to_string(),
238+
rustc_lint::builtin::UNUSED_DOC_COMMENTS.name.to_string(),
238239
// these are definitely not part of rustdoc, but we want to warn on them anyway.
239240
rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(),
240241
rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(),

tests/rustdoc-ui/check-doc-alias-attr-location.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pub trait Foo {
44
fn foo() -> Self::X;
55
}
66

7+
// FIXME(#96009): Don't emit `unused_doc_comments` here, we already emit an error anyway.
8+
//~v WARN
79
#[doc(alias = "foo")] //~ ERROR
810
extern "C" {}
911

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1+
warning: unused doc comment
2+
--> $DIR/check-doc-alias-attr-location.rs:9:1
3+
|
4+
LL | #[doc(alias = "foo")]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
LL | extern "C" {}
7+
| ------------- rustdoc does not generate documentation for extern blocks
8+
|
9+
= help: use `//` for a plain comment
10+
= note: `#[warn(unused_doc_comments)]` (part of `#[warn(unused)]`) on by default
11+
112
error: `#[doc(alias = "...")]` isn't allowed on foreign module
2-
--> $DIR/check-doc-alias-attr-location.rs:7:15
13+
--> $DIR/check-doc-alias-attr-location.rs:9:15
314
|
415
LL | #[doc(alias = "foo")]
516
| ^^^^^
617

718
error: `#[doc(alias = "...")]` isn't allowed on implementation block
8-
--> $DIR/check-doc-alias-attr-location.rs:10:15
19+
--> $DIR/check-doc-alias-attr-location.rs:12:15
920
|
1021
LL | #[doc(alias = "bar")]
1122
| ^^^^^
1223

1324
error: `#[doc(alias = "...")]` isn't allowed on implementation block
14-
--> $DIR/check-doc-alias-attr-location.rs:16:15
25+
--> $DIR/check-doc-alias-attr-location.rs:18:15
1526
|
1627
LL | #[doc(alias = "foobar")]
1728
| ^^^^^^^^
1829

1930
error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation block
20-
--> $DIR/check-doc-alias-attr-location.rs:18:19
31+
--> $DIR/check-doc-alias-attr-location.rs:20:19
2132
|
2233
LL | #[doc(alias = "assoc")]
2334
| ^^^^^^^
2435

25-
error: aborting due to 4 previous errors
36+
error: aborting due to 4 previous errors; 1 warning emitted
2637

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Ensure that lint `unused_doc_comments` also gets emitted by rustdoc, not just by rustc.
2+
//@ check-pass
3+
4+
pub fn f</** */T>() { //~ WARN unused doc comment
5+
/** */ let (); //~ WARN unused doc comment
6+
}
7+
8+
macro_rules! m { () => { pub fn g() {} } }
9+
10+
/** */ m!(); //~ WARN unused doc comment
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
warning: unused doc comment
2+
--> $DIR/unused-doc-comments.rs:10:1
3+
|
4+
LL | /** */ m!();
5+
| ^^^^^^ rustdoc does not generate documentation for macro invocations
6+
|
7+
= help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
8+
= note: `#[warn(unused_doc_comments)]` (part of `#[warn(unused)]`) on by default
9+
10+
warning: unused doc comment
11+
--> $DIR/unused-doc-comments.rs:4:10
12+
|
13+
LL | pub fn f</** */T>() {
14+
| ^^^^^^- rustdoc does not generate documentation for generic parameters
15+
|
16+
= help: use `/* */` for a plain comment
17+
18+
warning: unused doc comment
19+
--> $DIR/unused-doc-comments.rs:5:5
20+
|
21+
LL | /** */ let ();
22+
| ^^^^^^ ------- rustdoc does not generate documentation for statements
23+
|
24+
= help: use `/* */` for a plain comment
25+
26+
warning: 3 warnings emitted
27+

0 commit comments

Comments
 (0)