Emit warning when named arguments are used positionally in format
Addresses Issue 98466 by emitting a warning if a named argument is used like a position argument (i.e. the name is not used in the string to be formatted). Fixes rust-lang#98466
This commit is contained in:
parent
c80dde43f9
commit
1219f72f90
10 changed files with 324 additions and 16 deletions
|
@ -857,6 +857,18 @@ pub trait LintContext: Sized {
|
|||
Applicability::MachineApplicable,
|
||||
);
|
||||
},
|
||||
BuiltinLintDiagnostics::NamedArgumentUsedPositionally(positional_arg, named_arg, name) => {
|
||||
db.span_label(named_arg, "this named argument is only referred to by position in formatting string");
|
||||
let msg = format!("this formatting argument uses named argument `{}` by position", name);
|
||||
db.span_label(positional_arg, msg);
|
||||
db.span_suggestion_verbose(
|
||||
positional_arg,
|
||||
"use the named argument by name to avoid ambiguity",
|
||||
format!("{{{}}}", name),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
// Rewrap `db`, and pass control to the user.
|
||||
decorate(LintDiagnosticBuilder::new(db));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue