]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #91397 - jyn514:generic-param-docs, r=wesleywiser
authorMatthias Krüger <matthias.krueger@famsik.de>
Tue, 30 Nov 2021 22:43:33 +0000 (23:43 +0100)
committerGitHub <noreply@github.com>
Tue, 30 Nov 2021 22:43:33 +0000 (23:43 +0100)
Emit a warning on generic parameters with doc comments

Fixes https://github.com/rust-lang/rust/issues/90610

compiler/rustc_lint/src/builtin.rs
src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs
src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr

index f36b9c82fac4e167415a2552aec80d720d001d7b..077d3e1c82058bd055d33ed0b673571ab001c134 100644 (file)
@@ -1079,6 +1079,10 @@ fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
     fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
         warn_if_doc(cx, expr.span, "expressions", &expr.attrs);
     }
+
+    fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {
+        warn_if_doc(cx, param.ident.span, "generic parameters", &param.attrs);
+    }
 }
 
 declare_lint! {
index fd9baf8c6b9a28168e7433af05f1d3cd0ed15bb6..258f9e4831f9a3cddefc110f71cb43c55de0d763 100644 (file)
@@ -26,4 +26,7 @@ fn doc_comment_on_expr(num: u8) -> bool {
     num == 3
 }
 
+fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
+//~^ ERROR: unused doc comment
+
 fn main() {}
index 403367017c6e6e35e4c9f2a8bfa6034b72d769ba..3ce1df71a2ed58b9c41004cc102416075dde40fc 100644 (file)
@@ -41,6 +41,14 @@ LL |     num == 3
    |
    = help: use `//` for a plain comment
 
+error: unused doc comment
+  --> $DIR/unused-doc-comments-edge-cases.rs:29:27
+   |
+LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
+   |                           ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters
+   |
+   = help: use `//` for a plain comment
+
 error[E0308]: mismatched types
   --> $DIR/unused-doc-comments-edge-cases.rs:14:9
    |
@@ -55,7 +63,7 @@ help: you might have meant to return this value
 LL |         return true;
    |         ++++++     +
 
-error: aborting due to 5 previous errors
+error: aborting due to 6 previous errors
 
 Some errors have detailed explanations: E0308, E0658.
 For more information about an error, try `rustc --explain E0308`.