Skip to content

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

Closed
@8573

Description

@8573

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.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.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