Skip to content

Commit af8ae10

Browse files
committed
Generate correct suggestion with named arguments used positionally
Address issue rust-lang#99265 by checking each positionally used argument to see if the argument is named and adding a lint to use the name instead. This way, when named arguments are used positionally in a different order than their argument order, the suggested lint is correct. For example: ``` println!("{b} {}", a=1, b=2); ``` This will now generate the suggestion: ``` println!("{b} {a}", a=1, b=2); ``` Additionally, this check now also correctly replaces or inserts only where the positional argument is (or would be if implicit). Also, width and precision are replaced with their argument names when they exists. Since the issues were so closely related, this fix for issue rust-lang#99265 also fixes issue rust-lang#99266. Fixes rust-lang#99265 Fixes rust-lang#99266
1 parent 632f994 commit af8ae10

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clippy_lints/src/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl SimpleFormatArgs {
441441
};
442442

443443
match arg.position {
444-
ArgumentIs(n) | ArgumentImplicitlyIs(n) => {
444+
ArgumentIs(n, _) | ArgumentImplicitlyIs(n) => {
445445
if self.unnamed.len() <= n {
446446
// Use a dummy span to mark all unseen arguments.
447447
self.unnamed.resize_with(n, || vec![DUMMY_SP]);

0 commit comments

Comments
 (0)