-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest removing redundant arguments in format!() #115324
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
93df9e6
Suggest removing redundant arguments in format!()
francorbacho 4cc2d0b
Separate report_redundant_placeholders() into its own function
francorbacho 04fc051
Use diagnostic impls and add suggestions in redundant format!() args
francorbacho 9c921f8
Rename report_redundant_placeholders() to report_redundant_format_arg…
francorbacho e1c18f4
Document report_redundant_format_arguments()
francorbacho dc75c99
Remove unused variable
francorbacho 4a7a98c
Fix diagnostics being cancelled even with unused arguments
francorbacho fcdd5c0
Plurals in format redundant arguments suggestion
francorbacho 905bace
Highlight redundant arguments instead of the whole format string
francorbacho 38b0182
Add suggestion test
francorbacho c8ee7db
Only give autofix suggestion when no named args are present
francorbacho cbc6b65
Keep fluent slugs in alphabetical order
francorbacho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
fn main() { | ||
let x = "x"; | ||
let y = "y"; | ||
|
||
println!("{x}", x, x = y); | ||
//~^ ERROR: redundant argument | ||
|
||
println!("{x}", x = y, x = y); | ||
//~^ ERROR: duplicate argument named `x` | ||
} |
This file contains hidden or 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,22 @@ | ||
error: redundant argument | ||
--> $DIR/issue-105225-named-args.rs:5:21 | ||
| | ||
LL | println!("{x}", x, x = y); | ||
| ^ | ||
| | ||
note: the formatting specifier is referencing the binding already | ||
--> $DIR/issue-105225-named-args.rs:5:16 | ||
| | ||
LL | println!("{x}", x, x = y); | ||
| ^ | ||
|
||
error: duplicate argument named `x` | ||
--> $DIR/issue-105225-named-args.rs:8:28 | ||
| | ||
LL | println!("{x}", x = y, x = y); | ||
| - ^ duplicate argument | ||
| | | ||
| previously here | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or 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,21 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let x = "x"; | ||
let y = "y"; | ||
|
||
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 | ||
} |
This file contains hidden or 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,21 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let x = "x"; | ||
let y = "y"; | ||
|
||
println!("{x}", x); | ||
//~^ ERROR: redundant argument | ||
|
||
println!("{x} {}", x, x); | ||
//~^ ERROR: redundant argument | ||
|
||
println!("{} {x}", x, x); | ||
//~^ ERROR: redundant argument | ||
|
||
println!("{x} {y}", x, y); | ||
//~^ ERROR: redundant arguments | ||
|
||
println!("{} {} {x} {y} {}", x, x, x, y, y); | ||
//~^ ERROR: redundant arguments | ||
} |
This file contains hidden or 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,72 @@ | ||
error: redundant argument | ||
--> $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:7:16 | ||
| | ||
LL | println!("{x}", x); | ||
| ^ | ||
|
||
error: redundant argument | ||
--> $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:10:16 | ||
| | ||
LL | println!("{x} {}", x, x); | ||
| ^ | ||
|
||
error: redundant argument | ||
--> $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:13:19 | ||
| | ||
LL | println!("{} {x}", x, x); | ||
| ^ | ||
|
||
error: redundant arguments | ||
--> $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:16:16 | ||
| | ||
LL | println!("{x} {y}", x, y); | ||
| ^ ^ | ||
help: this can be removed | ||
| | ||
LL - println!("{x} {y}", x, y); | ||
LL + println!("{x} {y}", ); | ||
| | ||
|
||
error: redundant arguments | ||
--> $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:19:26 | ||
| | ||
LL | println!("{} {} {x} {y} {}", x, x, x, y, y); | ||
| ^ | ||
help: this can be removed | ||
| | ||
LL - println!("{} {} {x} {y} {}", x, x, x, y, y); | ||
LL + println!("{} {} {x} {y} {}", x, x, x, ); | ||
| | ||
|
||
error: aborting due to 5 previous errors | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.