Skip to content
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

Unhelpful error message because of inner line doc #65329

Closed
calixteman opened this issue Oct 12, 2019 · 0 comments · Fixed by #116965
Closed

Unhelpful error message because of inner line doc #65329

calixteman opened this issue Oct 12, 2019 · 0 comments · Fixed by #116965
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The 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

@calixteman
Copy link

The code

fn main() {
    let x = 0;
    let y = x.max(1) //!foo
        .min(2);
}

I get this error:

error: expected one of `.`, `;`, `?`, or an operator, found `//!foo`
 --> src/main.rs:3:22
  |
3 |     let y = x.max(1) //!foo
  |                      ^^^^^^ expected one of `.`, `;`, `?`, or an operator here

Probably something like:

error: expected outer doc comment
 --> src/main.rs:3:16
  |
3 |     let y = x; //!foo
  |                ^^^^^^
  |
  = note: inner doc comments like this (starting with `//!` or `/*!`) can only appear before items

is more helpful because at least you can understand what's wrong (especially when you don't know inner doc comments).

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The 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. labels Oct 12, 2019
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 20, 2023
Move where doc comment meant as comment check

The new place makes more sense and covers more cases beyond individual statements.

```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found doc comment `//!foo
  --> $DIR/doc-comment-in-stmt.rs:25:22
   |
LL |     let y = x.max(1) //!foo
   |                      ^^^^^^ expected one of `.`, `;`, `?`, `else`, or an operator
   |
help: add a space before `!` to write a regular comment
   |
LL |     let y = x.max(1) // !foo
   |                        +
```

Fix rust-lang#65329.
@bors bors closed this as completed in 20de5c7 Oct 20, 2023
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 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants