Change:
The same warning is produced at other places like statements, expressions, functions etc. For completeness and consistency it should be produced for pattern and expression fields too. No response rustc 1.74.0-nightly ( 2023-09-01) binary: rustc commit-hash: commit-date: 2023-09-01 host: x8664-pc-windows-msvc release: 1.74.0-nightly LLVM version: 17.0.0 rustc version older than 1.74.0 may ICE on this code. The ICE was fixed in 1.74.0 <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
The reason these warnings are not produced is because the lint infrastructure currently exposes no hooks for and , i.e. there are no and methods on (or for that matter). To fix the issue, these methods may have to be here: and then invoked from here: and here: Alternatively, we can emit the warning from the already existing and methods of and not bother with the above changes at all.
Yeah, I would expect this is the best way of doing it.
claim
label -needs-triage

Discussion:
warn_if_doc(cx, arm_span, "match arms", &arm.attrs); } <ins> fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat) { if let ast::PatKind::Struct(_, _, fields, _) = &pat.kind { for field in fields { warn_if_doc(cx, field.span, "pattern fields", &field.attrs); } } } </ins> fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { warn_if_doc(cx, expr.span, "expressions", &expr.attrs); <ins> if let ExprKind::Struct(s) = &expr.kind { for field in &s.fields { warn_if_doc(cx, field.span, "expression fields", &field.attrs); } } </ins> } fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {

subpattern: pattern, ascription: Ascription { annotation, <del> /// Note that use `Contravariant` here. See the /// `variance` field documentation for details. </del> <ins> // Note that use `Contravariant` here. See the // `variance` field documentation for details. </ins> variance: ty::Variance::Contravariant, }, },

num == 3 } <ins> fn doc_comment_on_expr_field() -> bool { struct S { foo: i32 } let x = S { /// useless doc comment //~^ ERROR: unused doc comment foo: 3 }; true } fn doc_comment_on_pat_field() -> bool { struct S { foo: i32 } let S { /// useless doc comment //~^ ERROR: unused doc comment foo } = S { foo: 3 }; true } </ins> fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} //~^ ERROR: unused doc comment

= help: use `//` for a plain comment error: unused doc comment <del> --> $DIR/unused-doc-comments-edge-cases.rs:29:27 </del> <ins> --> $DIR/unused-doc-comments-edge-cases.rs:33:9 | LL |         /// useless doc comment |         ^^^^^^^^^^^^^^^^^^^^^^^ LL | LL |         foo: 3 |         ------ rustdoc does not generate documentation for expression fields | = help: use `//` for a plain comment error: unused doc comment --> $DIR/unused-doc-comments-edge-cases.rs:45:9 | LL |         /// useless doc comment |         ^^^^^^^^^^^^^^^^^^^^^^^ LL | LL |         foo |         --- rustdoc does not generate documentation for pattern fields | = help: use `//` for a plain comment error: unused doc comment --> $DIR/unused-doc-comments-edge-cases.rs:55:27 </ins> | 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: unused doc comment <del> --> $DIR/unused-doc-comments-edge-cases.rs:33:5 </del> <ins> --> $DIR/unused-doc-comments-edge-cases.rs:59:5 </ins> | LL |       /// unused doc comment |       ^^^^^^^^^^^^^^^^^^^^^^

= help: use `//` for a plain comment error: unused doc comment <del> --> $DIR/unused-doc-comments-edge-cases.rs:40:1 </del> <ins> --> $DIR/unused-doc-comments-edge-cases.rs:66:1 </ins> | LL |   /// unused doc comment |   ^^^^^^^^^^^^^^^^^^^^^^

LL |         return true; |         ++++++     + <del> error: aborting due to 8 previous errors </del> <ins> error: aborting due to 10 previous errors </ins> Some errors have detailed explanations: E0308, E0658. For more information about an error, try `rustc --explain E0308`.