rust-clippy/tests/ui/unused_format_specs_unfixable.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

2022-10-13 12:13:54 +00:00
#![warn(clippy::unused_format_specs)]
#![allow(unused)]
2023-07-27 11:40:22 +00:00
//@no-rustfix
2022-10-13 12:13:54 +00:00
macro_rules! format_args_from_macro {
() => {
format_args!("from macro")
};
}
fn main() {
// prints `.`, not ` .`
println!("{:5}.", format_args!(""));
//~^ ERROR: format specifiers have no effect on `format_args!()`
//~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings`
2022-10-13 12:13:54 +00:00
//prints `abcde`, not `abc`
println!("{:.3}", format_args!("abcde"));
//~^ ERROR: format specifiers have no effect on `format_args!()`
2022-10-13 12:13:54 +00:00
println!("{:5}.", format_args_from_macro!());
//~^ ERROR: format specifiers have no effect on `format_args!()`
2022-10-13 12:13:54 +00:00
let args = format_args!("");
println!("{args:5}");
//~^ ERROR: format specifiers have no effect on `format_args!()`
2022-10-13 12:13:54 +00:00
}
fn should_not_lint() {
println!("{}", format_args!(""));
// Technically the same as `{}`, but the `format_args` docs specifically mention that you can use
// debug formatting so allow it
println!("{:?}", format_args!(""));
let args = format_args!("");
println!("{args}");
}