Skip to content

Commit 2902b92

Browse files
Only suggest if span is not erroneous
1 parent b71a09f commit 2902b92

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

Diff for: compiler/rustc_builtin_macros/src/format.rs

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

Diff for: compiler/rustc_lint/src/context.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -858,15 +858,16 @@ pub trait LintContext: Sized {
858858
},
859859
BuiltinLintDiagnostics::NamedArgumentUsedPositionally(positional_arg, named_arg, name) => {
860860
db.span_label(named_arg, "this named argument is only referred to by position in formatting string");
861-
let msg = format!("this formatting argument uses named argument `{}` by position", name);
862-
db.span_label(positional_arg, msg);
863-
db.span_suggestion_verbose(
864-
positional_arg,
865-
"use the named argument by name to avoid ambiguity",
866-
format!("{{{}}}", name),
867-
Applicability::MaybeIncorrect,
868-
);
869-
861+
if let Some(positional_arg) = positional_arg {
862+
let msg = format!("this formatting argument uses named argument `{}` by position", name);
863+
db.span_label(positional_arg, msg);
864+
db.span_suggestion_verbose(
865+
positional_arg,
866+
"use the named argument by name to avoid ambiguity",
867+
format!("{{{}}}", name),
868+
Applicability::MaybeIncorrect,
869+
);
870+
}
870871
}
871872
}
872873
// Rewrap `db`, and pass control to the user.

Diff for: compiler/rustc_lint_defs/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub enum BuiltinLintDiagnostics {
467467
/// If true, the lifetime will be fully elided.
468468
use_span: Option<(Span, bool)>,
469469
},
470-
NamedArgumentUsedPositionally(Span, Span, String),
470+
NamedArgumentUsedPositionally(Option<Span>, Span, String),
471471
}
472472

473473
/// Lints that are buffered up early on in the `Session` before the

0 commit comments

Comments
 (0)