mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 05:51:58 +00:00
Only suggest if span is not erroneous
This commit is contained in:
parent
b71a09fda0
commit
2902b92769
@ -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(),
|
||||
|
@ -858,15 +858,16 @@ pub trait LintContext: Sized {
|
||||
},
|
||||
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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user