Only suggest if span is not erroneous

This commit is contained in:
Michael Goulet 2022-07-15 17:32:15 +00:00
parent b71a09fda0
commit 2902b92769
3 changed files with 12 additions and 11 deletions

View File

@ -997,7 +997,7 @@ fn lint_named_arguments_used_positionally(
for (symbol, (index, span)) in names {
if !used_argument_names.contains(symbol.as_str()) {
let msg = format!("named argument `{}` is not used by name", symbol.as_str());
let arg_span = cx.arg_spans.get(index).copied().unwrap_or(span);
let arg_span = cx.arg_spans.get(index).copied();
cx.ecx.buffered_early_lint.push(BufferedEarlyLint {
span: MultiSpan::from_span(span),
msg: msg.clone(),

View File

@ -858,15 +858,16 @@ fn lookup_with_diagnostics(
},
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,
);
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(
positional_arg,
"use the named argument by name to avoid ambiguity",
format!("{{{}}}", name),
Applicability::MaybeIncorrect,
);
}
}
}
// Rewrap `db`, and pass control to the user.

View File

@ -467,7 +467,7 @@ pub enum BuiltinLintDiagnostics {
/// If true, the lifetime will be fully elided.
use_span: Option<(Span, bool)>,
},
NamedArgumentUsedPositionally(Span, Span, String),
NamedArgumentUsedPositionally(Option<Span>, Span, String),
}
/// Lints that are buffered up early on in the `Session` before the