diff options
| author | Alex Macleod <alex@macleod.io> | 2022-10-13 12:13:54 +0000 |
|---|---|---|
| committer | Alex Macleod <alex@macleod.io> | 2022-10-17 11:36:05 +0000 |
| commit | 136c2cdb910938103a762cdde177b1633bdbf99a (patch) | |
| tree | f4dc1f1c4bb258ebdd3b29784ef2355519387287 /src | |
| parent | 58ef56e39b434f5ce92154065b1d796e60355753 (diff) | |
Add `unused_format_specs` lint
Diffstat (limited to 'src')
| -rw-r--r-- | src/docs.rs | 1 | ||||
| -rw-r--r-- | src/docs/unused_format_specs.txt | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/docs.rs b/src/docs.rs index 41c31f91bca..33ea8488375 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -557,6 +557,7 @@ docs! { "unseparated_literal_suffix", "unsound_collection_transmute", "unused_async", + "unused_format_specs", "unused_io_amount", "unused_peekable", "unused_rounding", diff --git a/src/docs/unused_format_specs.txt b/src/docs/unused_format_specs.txt new file mode 100644 index 00000000000..77be3a2fb17 --- /dev/null +++ b/src/docs/unused_format_specs.txt @@ -0,0 +1,24 @@ +### What it does +Detects [formatting parameters] that have no effect on the output of +`format!()`, `println!()` or similar macros. + +### Why is this bad? +Shorter format specifiers are easier to read, it may also indicate that +an expected formatting operation such as adding padding isn't happening. + +### Example +``` +println!("{:.}", 1.0); + +println!("not padded: {:5}", format_args!("...")); +``` +Use instead: +``` +println!("{}", 1.0); + +println!("not padded: {}", format_args!("...")); +// OR +println!("padded: {:5}", format!("...")); +``` + +[formatting parameters]: https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters \ No newline at end of file |
