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

Error message is misleading for missing semicolon between raw string literal and attribute #95030

Closed
8573 opened this issue Mar 17, 2022 · 0 comments · Fixed by #96355
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@8573
Copy link

8573 commented Mar 17, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8b5f6ac92ab1ea3dbc9d74c8d63d7514

const A: &'static str = r""

// Test
#[test]
fn test() {}

The current output is:

error: too many `#` when terminating raw string
 --> src/lib.rs:4:1
  |
4 | #[test]
  | ^ help: remove the extra `#`
  |
  = note: the raw string started with 0 `#`s

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=28a29f9c008732dd3e7fc75455a4e325

fn main() {
    let s = r""

    #[cfg(unix)]
    fn u() {}
}

The current output is:

error: too many `#` when terminating raw string
 --> src/main.rs:4:5
  |
4 |     #[cfg(unix)]
  |     ^ help: remove the extra `#`
  |
  = note: the raw string started with 0 `#`s

The problem with the error message is that there is nothing wrong with the raw string literals (as rustc notes, they don't use any #s anyway); in particular, the raw string literals are not incorrectly terminated. Rather, it is the item declaration or statement that is terminated incorrectly, in that it is missing its terminating semicolon. Besides being misleading as to the problem with the code, the error message includes a suggestion that would only break the syntax further.

I suggest this is a minor issue, especially as no-one appears to have reported it yet.

This issue appears to apply to stable, beta, and nightly.

@8573 8573 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2022
@TaKO8Ki TaKO8Ki added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Mar 17, 2022
@estebank estebank self-assigned this Apr 24, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 25, 2022
…rors

Better handle too many `#` recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix rust-lang#95030.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 25, 2022
…rors

Better handle too many `#` recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix rust-lang#95030.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 25, 2022
…rors

Better handle too many `#` recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix rust-lang#95030.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 25, 2022
…rors

Better handle too many `#` recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix rust-lang#95030.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Apr 25, 2022
…rors

Better handle too many `#` recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix rust-lang#95030.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 25, 2022
…rors

Better handle too many `#` recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix rust-lang#95030.
@bors bors closed this as completed in 3587406 Apr 26, 2022
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 D-confusing Diagnostics: Confusing error or lint that should be reworked. 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.

3 participants