rust-lang / rust-lang/rust-clippy
`print_literal` suggestion fails if we use unicode for { }: \x7B \x7D
Open
Nobody has claimed this yet.
I-suggestion-causes-error
P-low
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
kinda niche..
Using the following flags
--force-warn clippy::print_literal
this code:
macro_rules! static_str {
() => { "Hello World" }
}
fn main() {
println!("{}", file!());
println!("{}", line!());
println!("{}", static_str!());
println!("{}", "\x7Ba\x7D \x7Bb\x7D");
}
caused the following diagnostics:
Checking _9678386ff9a4065e3028a54598b4f3fc290974d1 v0.1.0 (/tmp/icemaker_global_tempdir.dESjtcUkYIKG/icemaker_clippyfix_tempdir.FWxuE6MPCOF0/_9678386ff9a4065e3028a54598b4f3fc290974d1)
warning: literal with an empty format string
--> src/main.rs:9:20
|
9 | println!("{}", "\x7Ba\x7D \x7Bb\x7D");
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
= note: requested on the command line with `--force-warn clippy::print-literal`
help: try
|
9 - println!("{}", "\x7Ba\x7D \x7Bb\x7D");
9 + println!("\x7Ba\x7D \x7Bb\x7D");
|
warning: `_9678386ff9a4065e3028a54598b4f3fc290974d1` (bin "_9678386ff9a4065e3028a54598b4f3fc290974d1") generated 1 warning (run `cargo clippy --fix --bin "_9678386ff9a4065e3028a54598b4f3fc290974d1" -p _9678386ff9a4065e3028a54598b4f3fc290974d1` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s
However after applying these diagnostics, the resulting code:
macro_rules! static_str {
() => { "Hello World" }
}
fn main() {
println!("{}", file!());
println!("{}", line!());
println!("{}", static_str!());
println!("\x7Ba\x7D \x7Bb\x7D");
}
no longer compiled:
Checking _9678386ff9a4065e3028a54598b4f3fc290974d1 v0.1.0 (/tmp/icemaker_global_tempdir.dESjtcUkYIKG/icemaker_clippyfix_tempdir.FWxuE6MPCOF0/_9678386ff9a4065e3028a54598b4f3fc290974d1)
error[E0425]: cannot find value `a` in this scope
--> src/main.rs:9:19
|
9 | println!("\x7Ba\x7D \x7Bb\x7D");
| ^ not found in this scope
error[E0425]: cannot find value `b` in this scope
--> src/main.rs:9:29
|
9 | println!("\x7Ba\x7D \x7Bb\x7D");
| ^ not found in this scope
For more information about this error, try `rustc --explain E0425`.
error: could not compile `_9678386ff9a4065e3028a54598b4f3fc290974d1` (bin "_9678386ff9a4065e3028a54598b4f3fc290974d1" test) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `_9678386ff9a4065e3028a54598b4f3fc290974d1` (bin "_9678386ff9a4065e3028a54598b4f3fc290974d1") due to 2 previous errors
Version:
rustc 1.95.0-nightly (94a0cd15f 2026-01-27)
binary: rustc
commit-hash: 94a0cd15f5976fa35e5e6784e621c04e9f958e57
commit-date: 2026-01-27
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8
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
Start by locating the print_literal lint and the code that builds its suggestion, then reproduce the reported snippet with --force-warn clippy::print_literal. The fix is done when the suggested rewrite still compiles and preserves braces represented by \x7B and \x7D.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100