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.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 17, 2022
added
D-confusingDiagnostics: Confusing error or lint that should be reworked.
on Mar 17, 2022
self-assigned this
on Apr 24, 2022
added a commit that references this issue on Apr 25, 2022

Rollup merge of rust-lang#96355 - estebank:issue-95030, r=compiler-er…

0c81f90
added 3 commits that reference this issue on Apr 25, 2022

Rollup merge of rust-lang#96355 - estebank:issue-95030, r=compiler-er…

fd19bb2

Rollup merge of rust-lang#96355 - estebank:issue-95030, r=compiler-er…

2557101

Rollup merge of rust-lang#96355 - estebank:issue-95030, r=compiler-er…

c789833
added a commit that references this issue on Apr 25, 2022

Rollup merge of rust-lang#96355 - estebank:issue-95030, r=compiler-er…

9fe2d8a
added a commit that references this issue on Apr 25, 2022

Rollup merge of rust-lang#96355 - estebank:issue-95030, r=compiler-er…

77031f3

1 remaining item

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Participants

    @estebank@8573@TaKO8Ki

    Issue actions

      Error message is misleading for missing semicolon between raw string literal and attribute · Issue #95030 · rust-lang/rust