Skip to content

Confusing error message "this doc comment doesn't document anything" when there is a syntax error right after a comment #71982

Closed
@ipkiss42

Description

@ipkiss42

I tried this code:

/// Some documentation. Below "async" is before "pub" by mistake.
async pub fn hello() {}

fn main() {
}

I expected to see this happen: a clear error message telling me about the mistake (async before pub).

Instead, this happened:

error: expected item after doc comment
 --> src/main.rs:1:1
  |
1 | /// Some documentation. Below "async" is before "pub" by mistake.
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this doc comment doesn't document anything

This is a confusing error message. Without the comment, the error is clearer (though arguably still not completely obvious):

error: expected item, found keyword `async`
 --> src/main.rs:1:1
  |
1 | async pub fn hello() {}
  | ^^^^^ expected item

Meta

rustc --version --verbose:

rustc 1.43.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.43.0
LLVM version: 10.0
Backtrace

No backtrace.

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 ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.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