Closed
Description
I tried this code:
fn main() {
let r#type = "foobar";
println!("It is {r#type}");
}
I expected to see this happen: The program compiles and prints "It is foobar" to stdout.
Instead, this happened: The compiler gives an error while compiling: "error: invalid format string"
Meta
rustc --version --verbose
:
(Only tested on playground, but on all three channels, reported as:)
1.74.0-nightly 2023-09-01 35e416303e6591a71ef6
1.73.0-beta.4 2023-09-01 9f37cd4f79d289492cca
1.72.0
It's not a compiler crash, so I'm going to leave out the backtrace and instead just show what the compiler outputs when you try to compile the above code:
error: invalid format string: expected `'}'`, found `'#'`
--> src/main.rs:3:23
|
3 | println!("It is {r#type}");
| - ^ expected `'}'` in format string
| |
| because of this opening brace
|
= note: if you intended to print `{`, you can escape it using `{{`
I'm not convinced this is solvable/possible (I can imagine allowing this could potentially interfere with other formatting options (although they all follow a :
, right? So maybe not.), but I also couldn't find any existing issue about it, so I figured I'd open one to have it clarified.