Skip to content

Commit 7baafb1

Browse files
authored
Rollup merge of #91397 - jyn514:generic-param-docs, r=wesleywiser
Emit a warning on generic parameters with doc comments Fixes #90610
2 parents 2b8259a + bd894a0 commit 7baafb1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/rustc_lint/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,10 @@ impl EarlyLintPass for UnusedDocComment {
10791079
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
10801080
warn_if_doc(cx, expr.span, "expressions", &expr.attrs);
10811081
}
1082+
1083+
fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {
1084+
warn_if_doc(cx, param.ident.span, "generic parameters", &param.attrs);
1085+
}
10821086
}
10831087

10841088
declare_lint! {

src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ fn doc_comment_on_expr(num: u8) -> bool {
2626
num == 3
2727
}
2828

29+
fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
30+
//~^ ERROR: unused doc comment
31+
2932
fn main() {}

src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ LL | num == 3
4141
|
4242
= help: use `//` for a plain comment
4343

44+
error: unused doc comment
45+
--> $DIR/unused-doc-comments-edge-cases.rs:29:27
46+
|
47+
LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
48+
| ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters
49+
|
50+
= help: use `//` for a plain comment
51+
4452
error[E0308]: mismatched types
4553
--> $DIR/unused-doc-comments-edge-cases.rs:14:9
4654
|
@@ -55,7 +63,7 @@ help: you might have meant to return this value
5563
LL | return true;
5664
| ++++++ +
5765

58-
error: aborting due to 5 previous errors
66+
error: aborting due to 6 previous errors
5967

6068
Some errors have detailed explanations: E0308, E0658.
6169
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)