rust-lang / rust-lang/rust

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

Open
#140,618 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided raw-string snippet using the reported Rust nightly version and compare the current and desired diagnostics. Trace the compiler handling for raw-string termination and reserved multi-hash tokens; done means the malformed input produces one focused error identifying the extra # and the number used to start the raw string.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.