-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #9605 - nyurik:fix-inline-edition, r=llogiq
fix: uninlined_format_args shouldn't inline panic! before 2021ed Before 2021 edition, `panic!("...")` was not treated as a format string. Clippy autofix of `panic!("{}", foo)` into `panic!("{foo}")` is incorrect. changelog: [`uninlined_format_args`]: Do not inline panic! macros before 2021 edition
- Loading branch information
Showing
10 changed files
with
239 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// run-rustfix | ||
// edition:2018 | ||
|
||
#![warn(clippy::uninlined_format_args)] | ||
|
||
fn main() { | ||
let var = 1; | ||
|
||
println!("val='{var}'"); | ||
|
||
if var > 0 { | ||
panic!("p1 {}", var); | ||
} | ||
if var > 0 { | ||
panic!("p2 {0}", var); | ||
} | ||
if var > 0 { | ||
panic!("p3 {var}", var = var); | ||
} | ||
|
||
#[allow(non_fmt_panics)] | ||
{ | ||
if var > 0 { | ||
panic!("p4 {var}"); | ||
} | ||
} | ||
} |
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,27 @@ | ||
// run-rustfix | ||
// edition:2018 | ||
|
||
#![warn(clippy::uninlined_format_args)] | ||
|
||
fn main() { | ||
let var = 1; | ||
|
||
println!("val='{}'", var); | ||
|
||
if var > 0 { | ||
panic!("p1 {}", var); | ||
} | ||
if var > 0 { | ||
panic!("p2 {0}", var); | ||
} | ||
if var > 0 { | ||
panic!("p3 {var}", var = var); | ||
} | ||
|
||
#[allow(non_fmt_panics)] | ||
{ | ||
if var > 0 { | ||
panic!("p4 {var}"); | ||
} | ||
} | ||
} |
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,15 @@ | ||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args_2018.rs:9:5 | ||
| | ||
LL | println!("val='{}'", var); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::uninlined-format-args` implied by `-D warnings` | ||
help: change this to | ||
| | ||
LL - println!("val='{}'", var); | ||
LL + println!("val='{var}'"); | ||
| | ||
|
||
error: aborting due to previous error | ||
|
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,23 @@ | ||
// run-rustfix | ||
// edition:2021 | ||
|
||
#![warn(clippy::uninlined_format_args)] | ||
|
||
fn main() { | ||
let var = 1; | ||
|
||
println!("val='{var}'"); | ||
|
||
if var > 0 { | ||
panic!("p1 {var}"); | ||
} | ||
if var > 0 { | ||
panic!("p2 {var}"); | ||
} | ||
if var > 0 { | ||
panic!("p3 {var}"); | ||
} | ||
if var > 0 { | ||
panic!("p4 {var}"); | ||
} | ||
} |
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,23 @@ | ||
// run-rustfix | ||
// edition:2021 | ||
|
||
#![warn(clippy::uninlined_format_args)] | ||
|
||
fn main() { | ||
let var = 1; | ||
|
||
println!("val='{}'", var); | ||
|
||
if var > 0 { | ||
panic!("p1 {}", var); | ||
} | ||
if var > 0 { | ||
panic!("p2 {0}", var); | ||
} | ||
if var > 0 { | ||
panic!("p3 {var}", var = var); | ||
} | ||
if var > 0 { | ||
panic!("p4 {var}"); | ||
} | ||
} |
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,51 @@ | ||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args_2021.rs:9:5 | ||
| | ||
LL | println!("val='{}'", var); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::uninlined-format-args` implied by `-D warnings` | ||
help: change this to | ||
| | ||
LL - println!("val='{}'", var); | ||
LL + println!("val='{var}'"); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args_2021.rs:12:9 | ||
| | ||
LL | panic!("p1 {}", var); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - panic!("p1 {}", var); | ||
LL + panic!("p1 {var}"); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args_2021.rs:15:9 | ||
| | ||
LL | panic!("p2 {0}", var); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - panic!("p2 {0}", var); | ||
LL + panic!("p2 {var}"); | ||
| | ||
|
||
error: variables can be used directly in the `format!` string | ||
--> $DIR/uninlined_format_args_2021.rs:18:9 | ||
| | ||
LL | panic!("p3 {var}", var = var); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: change this to | ||
| | ||
LL - panic!("p3 {var}", var = var); | ||
LL + panic!("p3 {var}"); | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|