-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Confusing error message "this doc comment doesn't document anything" when there is a syntax error right after a comment #71982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-parser
Area: The lexing & parsing of Rust source code to an AST
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
Agreed, I just hit this as well. It also seems to be inconsistent based on the syntax error. For example, a missing identifier syntax error outputs a helpful error /// hello world
async fn {}
while a different syntax error prints out a different error than the first one: /// hello world
<>
|
Current output:
The following case is still subpar
|
The following code snippet can trigger this bug as well: enum TestEnum {
Works,
/// Some documentation
Self,
} Current output:
Expected output:
|
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Feb 19, 2025
… r=compiler-errors Tweak "expected ident" parse error to avoid talking about doc comments When encountering a doc comment without an identifier after, we'd unconditionally state "this doc comment doesn't document anything", swallowing the *actual* error which is that the thing *after* the doc comment wasn't expected. Added a check that the found token is something that "conceptually" closes the previous item before emitting that error, otherwise just complain about the missing identifier. In both of the following cases, the syntax error follows a doc comment: ``` error: expected identifier, found keyword `Self` --> $DIR/doc-before-bad-variant.rs:4:5 | LL | enum TestEnum { | -------- while parsing this enum ... LL | Self, | ^^^^ expected identifier, found keyword | = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }` ``` ``` error: expected identifier, found `<` --> $DIR/doc-before-syntax-error.rs:2:1 | LL | <> | ^ expected identifier ``` Fix rust-lang#71982.
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 20, 2025
Rollup merge of rust-lang#137281 - estebank:doc-comment-syntax-error, r=compiler-errors Tweak "expected ident" parse error to avoid talking about doc comments When encountering a doc comment without an identifier after, we'd unconditionally state "this doc comment doesn't document anything", swallowing the *actual* error which is that the thing *after* the doc comment wasn't expected. Added a check that the found token is something that "conceptually" closes the previous item before emitting that error, otherwise just complain about the missing identifier. In both of the following cases, the syntax error follows a doc comment: ``` error: expected identifier, found keyword `Self` --> $DIR/doc-before-bad-variant.rs:4:5 | LL | enum TestEnum { | -------- while parsing this enum ... LL | Self, | ^^^^ expected identifier, found keyword | = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }` ``` ``` error: expected identifier, found `<` --> $DIR/doc-before-syntax-error.rs:2:1 | LL | <> | ^ expected identifier ``` Fix rust-lang#71982.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-parser
Area: The lexing & parsing of Rust source code to an AST
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried this code:
I expected to see this happen: a clear error message telling me about the mistake (
async
beforepub
).Instead, this happened:
This is a confusing error message. Without the comment, the error is clearer (though arguably still not completely obvious):
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: