Guarded byte string and C string non-raw literals should not report "unknown prefix"
Open
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
macro_rules! a {
($($t:tt)*) => {};
}
a! {
b#""#
c#""#
}
Current output
Compiling playground v0.0.1 (/playground)
error: prefix `b` is unknown
--> src/lib.rs:6:3
|
6 | b#""#
| ^ unknown prefix
|
= note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
|
6 | b #""#
| +
error: invalid string literal
--> src/lib.rs:6:4
|
6 | b#""#
| ^^^^
|
= note: unprefixed guarded string literals are reserved for future use since Rust 2024
help: consider inserting whitespace here
|
6 | b# ""#
| +
error: prefix `c` is unknown
--> src/lib.rs:7:3
|
7 | c#""#
| ^ unknown prefix
|
= note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
|
7 | c #""#
| +
error: invalid string literal
--> src/lib.rs:7:4
|
7 | c#""#
| ^^^^
|
= note: unprefixed guarded string literals are reserved for future use since Rust 2024
help: consider inserting whitespace here
|
7 | c# ""#
| +
error: could not compile `playground` (lib) due to 4 previous errors
Desired output
Compiling playground v0.0.1 (/playground)
error: invalid string literal
--> src/lib.rs:6:4
|
6 | b#""#
| ^^ ^
|
= note: guarded byte string literals are not supported
help: did you mean to write a raw byte string literal?
|
6 | br#""#
| +
error: invalid string literal
--> src/lib.rs:7:4
|
7 | c#""#
| ^^ ^
|
= note: guarded C string literals are not supported
help: did you mean to write a raw C string literal?
|
7 | cr#""#
| +
error: could not compile `playground` (lib) due to 2 previous errors
Rationale and extra context
The error message prefix `b` is unknown is incorrect. The prefix b for string literals does mean something, just not for guarded string literals.
Rust Version
1.88.0-nightly (2025-04-02 d5b4c2e4f19b6d703737)
(sorry this isn't the rustc --version --verbose output asked; i've tested with the online playground only)
Anything else?
Cursor::c_or_byte_string should lex a # character and produce a different error token than UnknownPrefix. It currently doesn't.
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 Rust snippet, then read Cursor::c_or_byte_string in compiler/rustc_lexer/src/lib.rs around the referenced line. Trace how the # character is handled for b and c literals; done means the diagnostics match the desired output without separate unknown-prefix errors.
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
- Clearly specified
- Newbie friendliness
- 45/100