Only suggest if span is not erroneous
This commit is contained in:
parent
b71a09fda0
commit
2902b92769
3 changed files with 12 additions and 11 deletions
|
@ -997,7 +997,7 @@ fn lint_named_arguments_used_positionally(
|
||||||
for (symbol, (index, span)) in names {
|
for (symbol, (index, span)) in names {
|
||||||
if !used_argument_names.contains(symbol.as_str()) {
|
if !used_argument_names.contains(symbol.as_str()) {
|
||||||
let msg = format!("named argument `{}` is not used by name", 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 {
|
cx.ecx.buffered_early_lint.push(BufferedEarlyLint {
|
||||||
span: MultiSpan::from_span(span),
|
span: MultiSpan::from_span(span),
|
||||||
msg: msg.clone(),
|
msg: msg.clone(),
|
||||||
|
|
|
@ -858,15 +858,16 @@ pub trait LintContext: Sized {
|
||||||
},
|
},
|
||||||
BuiltinLintDiagnostics::NamedArgumentUsedPositionally(positional_arg, named_arg, name) => {
|
BuiltinLintDiagnostics::NamedArgumentUsedPositionally(positional_arg, named_arg, name) => {
|
||||||
db.span_label(named_arg, "this named argument is only referred to by position in formatting string");
|
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);
|
if let Some(positional_arg) = positional_arg {
|
||||||
db.span_label(positional_arg, msg);
|
let msg = format!("this formatting argument uses named argument `{}` by position", name);
|
||||||
db.span_suggestion_verbose(
|
db.span_label(positional_arg, msg);
|
||||||
positional_arg,
|
db.span_suggestion_verbose(
|
||||||
"use the named argument by name to avoid ambiguity",
|
positional_arg,
|
||||||
format!("{{{}}}", name),
|
"use the named argument by name to avoid ambiguity",
|
||||||
Applicability::MaybeIncorrect,
|
format!("{{{}}}", name),
|
||||||
);
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Rewrap `db`, and pass control to the user.
|
// Rewrap `db`, and pass control to the user.
|
||||||
|
|
|
@ -467,7 +467,7 @@ pub enum BuiltinLintDiagnostics {
|
||||||
/// If true, the lifetime will be fully elided.
|
/// If true, the lifetime will be fully elided.
|
||||||
use_span: Option<(Span, bool)>,
|
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
|
/// Lints that are buffered up early on in the `Session` before the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue