Skip to content

Doc comments present after a particular syntax error cause an unhelpful error message to be output. #48636

Closed
@toor

Description

@toor

I had this code:

pub struct LocalApic {
    pub id: u8
    /// The id of the parent core
    pub processor_id: u8,
    // ...
}

The actual error of course here, would be that there is a missing comma after the pub id: u8.
However the error message given by the compiler was:

error[E0585]: found a documentation comment that doesn't document anything
  --> src/device/apic.rs:16:5
   |
16 |     /// The id of the parent core.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: doc comments must come before what they document, maybe a comment was intended with //?

which is irrelevant to the actual error present in the code and does nothing but mislead the programmer IMO.

It is worth noting that attaching #[doc] to the line pub processor_id: u8 does give the expected error:

error: expected `,`, or `}`, found `#`
  --> src/device/apic.rs:16:5
   |
16 |     #[doc = "The id of the parent core"]
   |     ^
   |
   = help: struct fields should be separated by commas

This isn't a particularly important issue, but as mentioned by someone I spoke to regarding this error, the error messages given by the compiler are usually very helpful, and I feel it is worth maintaining this standard.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions