Raw strings w/ too many terminating hashes are not exclusively handled
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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