Description
Look at the following snippet:
println!("{} {}", crate_name!(), crate_description!());
In this code, crate_name!()
and crate_description!()
are macros provided by the clap
crate. These two macros return a &str
.
This snippet produces the following clippy
warnings:
warning: printing a literal with an empty format string
--> src/main.rs:5:23
|
5 | println!("{} {}", crate_name!(), crate_description!());
| ^^^^^^^^^^^^^
|
= note: #[warn(print_literal)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.198/index.html#print_literal
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
warning: printing a literal with an empty format string
--> src/main.rs:5:38
|
5 | println!("{} {}", crate_name!(), crate_description!());
| ^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.198/index.html#print_literal
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
I believe these warnings are incorrect in this situation, and I don't see a way of improving this statement.
Is this some edge case for which the warning shouldn't be triggered, thus requiring a lint change? Or am I thinking wrong?
Of course, when only a single macro is used it can be printed directly:
println!(crate_name!());
However, this snippet uses two macros and one of these implementations wouldn't work as the first parameter isn't a valid format string:
println!(crate_name!(), " ", crate_description!());
println!(crate_name!(), crate_description!()); // Also missing a space
A code example that produces this clippy
warning can be found on the playground.
The warnings might be correct, and I might have missed something. In that case; sorry.