Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest removing redundant arguments in format!() #115324

Merged
merged 12 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add suggestion test
  • Loading branch information
francorbacho committed Oct 5, 2023
commit 38b01828328014708feb48f9cdc065460e651098
21 changes: 21 additions & 0 deletions tests/ui/did_you_mean/issue-105225.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-rustfix

fn main() {
let x = 0;
let y = 0;

println!("{x}", );
//~^ ERROR: redundant argument

println!("{x} {}", x, );
//~^ ERROR: redundant argument

println!("{} {x}", x, );
//~^ ERROR: redundant argument

println!("{x} {y}", );
//~^ ERROR: redundant arguments

println!("{} {} {x} {y} {}", x, x, x, );
//~^ ERROR: redundant arguments
}
2 changes: 2 additions & 0 deletions tests/ui/did_you_mean/issue-105225.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// run-rustfix

fn main() {
let x = 0;
let y = 0;
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/did_you_mean/issue-105225.stderr
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
error: redundant argument
--> $DIR/issue-105225.rs:5:21
--> $DIR/issue-105225.rs:7:21
|
LL | println!("{x}", x);
| ^ help: this can be removed
|
note: the formatting specifier is referencing the binding already
--> $DIR/issue-105225.rs:5:16
--> $DIR/issue-105225.rs:7:16
|
LL | println!("{x}", x);
| ^

error: redundant argument
--> $DIR/issue-105225.rs:8:27
--> $DIR/issue-105225.rs:10:27
|
LL | println!("{x} {}", x, x);
| ^ help: this can be removed
|
note: the formatting specifier is referencing the binding already
--> $DIR/issue-105225.rs:8:16
--> $DIR/issue-105225.rs:10:16
|
LL | println!("{x} {}", x, x);
| ^

error: redundant argument
--> $DIR/issue-105225.rs:11:27
--> $DIR/issue-105225.rs:13:27
|
LL | println!("{} {x}", x, x);
| ^ help: this can be removed
|
note: the formatting specifier is referencing the binding already
--> $DIR/issue-105225.rs:11:19
--> $DIR/issue-105225.rs:13:19
|
LL | println!("{} {x}", x, x);
| ^

error: redundant arguments
--> $DIR/issue-105225.rs:14:25
--> $DIR/issue-105225.rs:16:25
|
LL | println!("{x} {y}", x, y);
| ^ ^
|
note: the formatting specifiers are referencing the bindings already
--> $DIR/issue-105225.rs:14:16
--> $DIR/issue-105225.rs:16:16
|
LL | println!("{x} {y}", x, y);
| ^ ^
Expand All @@ -52,13 +52,13 @@ LL + println!("{x} {y}", );
|

error: redundant arguments
--> $DIR/issue-105225.rs:17:43
--> $DIR/issue-105225.rs:19:43
|
LL | println!("{} {} {x} {y} {}", x, x, x, y, y);
| ^ ^
|
note: the formatting specifiers are referencing the bindings already
--> $DIR/issue-105225.rs:17:26
--> $DIR/issue-105225.rs:19:26
|
LL | println!("{} {} {x} {y} {}", x, x, x, y, y);
| ^
Expand Down