forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#9637 - Alexendoo:unused-format-specs, r=xFrednet
Add `unused_format_specs` lint Currently catches two cases: An empty precision specifier: ```rust // the same as {} println!("{:.}", x); ``` And using formatting specs on `format_args!()`: ```rust // prints `x.`, not `x .` println("{:5}.", format_args!("x")); ``` changelog: new lint: [`unused_format_specs`]
- Loading branch information
Showing
13 changed files
with
384 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::unused_format_specs)] | ||
#![allow(unused)] | ||
|
||
fn main() { | ||
let f = 1.0f64; | ||
println!("{}", 1.0); | ||
println!("{f} {f:?}"); | ||
|
||
println!("{}", 1); | ||
} | ||
|
||
fn should_not_lint() { | ||
let f = 1.0f64; | ||
println!("{:.1}", 1.0); | ||
println!("{f:.w$} {f:.*?}", 3, w = 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::unused_format_specs)] | ||
#![allow(unused)] | ||
|
||
fn main() { | ||
let f = 1.0f64; | ||
println!("{:.}", 1.0); | ||
println!("{f:.} {f:.?}"); | ||
|
||
println!("{:.}", 1); | ||
} | ||
|
||
fn should_not_lint() { | ||
let f = 1.0f64; | ||
println!("{:.1}", 1.0); | ||
println!("{f:.w$} {f:.*?}", 3, w = 2); | ||
} |
Oops, something went wrong.