Skip to content

Raw strings w/ too many terminating hashes are not exclusively handled #140618

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

Open
md-tr opened this issue May 3, 2025 · 0 comments
Open

Raw strings w/ too many terminating hashes are not exclusively handled #140618

md-tr opened this issue May 3, 2025 · 0 comments
Labels
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.

Comments

@md-tr
Copy link

md-tr commented May 3, 2025

Code

fn main() {
    r#"ok!"###;
}

Current output

error: reserved multi-hash token is forbidden
 --> src/main.rs:2:13
  |
2 |     r#"ok!"###;
  |             ^^
  |
  = note: sequences of two or more # are reserved for future use since Rust 2024
help: consider inserting whitespace here
  |
2 |     r#"ok!"## #;
  |              +

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `##`
 --> src/main.rs:2:13
  |
2 |     r#"ok!"###;
  |             ^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: could not compile `playground` (bin "playground") due to 2 previous errors

Desired output

error: too many `#` when terminating raw string
 --> src/main.rs:2:13
  |
2 |     r#"ok!"###;
  |     --------^^ help: remove the extra `#`
  |     |
  |     this raw string started with 1 `#`

error: could not compile `playground` (bin "playground") due to 1 previous error

Rationale and extra context

rustc is already capable of warning the user if a raw string is found to be finalized with one more octothorpe (#) than expected. To avoid confusion, the compiler reserves multi-hash tokens, ensuring that ### and #"foo"# are not interpreted as three separate tokens in macro invocations (see here). However, in my opinion, raw strings whose terminators are followed by one or more '#' characters may not create an edge case. They must already be recognized by the compiler as a "malformed token."

Rust Version

rustc 1.88.0-nightly (4824c2bb7 2025-05-02)
binary: rustc
commit-hash: 4824c2bb7445cb2478aab0190c268c939d77a0f6
commit-date: 2025-05-02
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Anything else?

No response

@md-tr md-tr 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 May 3, 2025
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant