Closed
Description
Summary
When using file!()
as a macro inside of println!
, it suggest to replace it.
The suggestion leads to invalid code.
The error was probably introduces in 6fc6d87 @Alexendoo
As shown in the code below, other macro calls work fine, it seems to be a problem with the file!()
macro in particular.
Maybe checking && value_string != "file!()"
would be a valid solution here?!
rust-clippy/clippy_lints/src/write.rs
Line 463 in 27edc2a
Lint Name
print_literal
Reproducer
I tried this code:
macro_rules! static_str {
() => { "Hello World" }
}
fn main() {
println!("{}", file!());
println!("{}", line!());
println!("{}", static_str!());
println!("{}", "Hello World");
}
I saw this happen:
warning: literal with an empty format string
--> src/main.rs:6:20
|
6 | println!("{}", file!());
| ^^^^^^^
|
= note: `#[warn(clippy::print_literal)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
help: try this
|
6 - println!("{}", file!());
6 + println!("ile!(");
|
warning: literal with an empty format string
--> src/main.rs:9:20
|
9 | println!("{}", "Hello World");
| ^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
help: try this
|
9 - println!("{}", "Hello World");
9 + println!("Hello World");
|
warning: `abc` (bin "abc") generated 2 warnings
I expected to see this happen:
Not issuing the first warning, but only the second
Version
rustc 1.66.0-nightly (f5193a9fc 2022-09-25)
binary: rustc
commit-hash: f5193a9fcc73dc09e41a90c5a2c97fc9acc16032
commit-date: 2022-09-25
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0
Additional Labels
@rustbot label +I-suggestion-causes-error