-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 #9865 - nyurik:allow-mixed, r=xFrednet
Add allow-mixed-uninlined-format-args config Implement `allow-mixed-uninlined-format-args` config param to change the behavior of the `uninlined_format_args` lint. Now it is a part of `style` per [Zulip chat](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60uninlined_format_args.60.20category), and won't propose inlining in case of a mixed usage, e.g. `print!("{} {}", var, 1+2)`. If the user sets `allow-mixed-uninlined-format-args` config param to `false`, the lint would behave like it did before -- proposing to inline args even in the mixed case. --- changelog: [`uninlined_format_args`]: Added a new config `allow-mixed-uninlined-format-args` to allow the lint, if only some arguments can be inlined [#9865](#9865) changelog: Moved [`uninlined_format_args`] to `style` (Now warn-by-default) [#9865](#9865)
- Loading branch information
Showing
10 changed files
with
156 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
allow-mixed-uninlined-format-args = false |
14 changes: 14 additions & 0 deletions
14
tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
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,14 @@ | ||
// run-rustfix | ||
#![warn(clippy::uninlined_format_args)] | ||
|
||
fn main() { | ||
let local_i32 = 1; | ||
let local_f64 = 2.0; | ||
let local_opt: Option<i32> = Some(3); | ||
|
||
println!("val='{local_i32}'"); | ||
println!("Hello x is {local_f64:.local_i32$}"); | ||
println!("Hello {local_i32} is {local_f64:.*}", 5); | ||
println!("Hello {local_i32} is {local_f64:.*}", 5); | ||
println!("{local_i32}, {}", local_opt.unwrap()); | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
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,14 @@ | ||
// run-rustfix | ||
#![warn(clippy::uninlined_format_args)] | ||
|
||
fn main() { | ||
let local_i32 = 1; | ||
let local_f64 = 2.0; | ||
let local_opt: Option<i32> = Some(3); | ||
|
||
println!("val='{}'", local_i32); | ||
println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ||
println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ||
println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ||
println!("{}, {}", local_i32, local_opt.unwrap()); | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
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,76 @@ | ||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args.rs:9:5 | ||
| | ||
LL | println!("val='{}'", local_i32); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::uninlined-format-args` implied by `-D warnings` | ||
help: change this to | ||
| | ||
LL - println!("val='{}'", local_i32); | ||
LL + println!("val='{local_i32}'"); | ||
| | ||
|
||
error: literal with an empty format string | ||
--> $DIR/uninlined_format_args.rs:10:35 | ||
| | ||
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ||
| ^^^ | ||
| | ||
= note: `-D clippy::print-literal` implied by `-D warnings` | ||
help: try this | ||
| | ||
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ||
LL + println!("Hello x is {:.*}", local_i32, local_f64); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args.rs:10:5 | ||
| | ||
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ||
LL + println!("Hello {} is {local_f64:.local_i32$}", "x"); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args.rs:11:5 | ||
| | ||
LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ||
LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args.rs:12:5 | ||
| | ||
LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ||
LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args.rs:13:5 | ||
| | ||
LL | println!("{}, {}", local_i32, local_opt.unwrap()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - println!("{}, {}", local_i32, local_opt.unwrap()); | ||
LL + println!("{local_i32}, {}", local_opt.unwrap()); | ||
| | ||
|
||
error: aborting due to 6 previous errors | ||
|
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