Generate correct suggestion with named arguments used positionally
Address issue #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 #99265 also fixes issue #99266. Fixes #99265 Fixes #99266
This commit is contained in:
parent
530c0a81d5
commit
3330c7d1c3
12 changed files with 1093 additions and 102 deletions
|
@ -861,10 +861,10 @@ pub trait LintContext: Sized {
|
|||
if let Some(positional_arg) = positional_arg {
|
||||
let msg = format!("this formatting argument uses named argument `{}` by position", name);
|
||||
db.span_label(positional_arg, msg);
|
||||
db.span_suggestion_verbose(
|
||||
db.span_suggestion_verbose(
|
||||
positional_arg,
|
||||
"use the named argument by name to avoid ambiguity",
|
||||
format!("{{{}}}", name),
|
||||
name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue