This code (playground):
macro_rules! impl_fmt_debug {
($id:ident) => {
impl std::fmt::Debug for $id {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "|{}|", stringify!($id))
}
}
}
}
struct Foo();
impl_fmt_debug!(Foo);
fn main() {}
produces this lint:
warning: writing a literal with an empty format string
--> src/main.rs:5:35
|
5 | write!(f, "|{}|", stringify!($id))
| ^^^^^^^^^^^^^^^
...
13 | impl_fmt_debug!(Foo);
| --------------------- in this macro invocation
|
= note: #[warn(write_literal)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.211/index.html#write_literal
The lint documentation is pretty unhelpful about how to fix this, that is, how can I interpolate the result of stringify!($id) into the format string for this particular case within a macro?
cc @oli-obk @Manishearth this might be a bug
This is documented in the Known Problems section of the lint. Nevertheless it is indeed a bug, which would be nice if it could be fixed!
well.... you could do concat!("|", stringify!($id), "|"). But yea, we should not produce this lint for string literals produced by macros
The playground code does not trigger this lint any more. (Probably related to https://github.com/rust-lang-nursery/rust-clippy/pull/2949).
Most helpful comment
The playground code does not trigger this lint any more. (Probably related to https://github.com/rust-lang-nursery/rust-clippy/pull/2949).