Skip to content

Confusing error message from a missing comma #141403

Open
@pacak

Description

@pacak

Code

#[derive(Clone)]
struct B<T> {
    a: A<(T, u32)> // <- note, comma is missing here
    /// asdf
    b: u32,
}

Current output

error[E0585]: found a documentation comment that doesn't document anything
 --> src/lib.rs:4:5
  |
2 | struct B<T> {
  |        - while parsing this struct
3 |     a: A<(T, u32)>
4 |     /// asdf
  |     ^^^^^^^^
  |
  = help: doc comments must come before what they document, if a comment was intended use `//`
help: missing comma here
  |
3 |     a: A<(T, u32)>,
  |                   +

error[E0392]: type parameter `T` is never used
 --> src/lib.rs:2:10
  |
2 | struct B<T> {
  |          ^ unused type parameter
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

error[E0282]: type annotations needed
 --> src/lib.rs:1:10
  |
1 | #[derive(Clone)]
  |          ^ cannot infer type

Desired output

help: missing comma here
  |
3 |     a: A<(T, u32)>,
  |                   +

Rationale and extra context

Rust analyzer, at least in my setup with neovim error related to missing comma is the least visible of them. Error in code generated by #[derive(Clone)] is confusing.

Other cases

Rust Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions