Skip to content

Commit b71a09f

Browse files
Fix ICE in named_arguments_used_positionally lint
1 parent 0fe5390 commit b71a09f

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

compiler/rustc_builtin_macros/src/format.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use smallvec::SmallVec;
1616

1717
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
1818
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, LintId};
19-
use rustc_parse_format::{Count, FormatSpec};
19+
use rustc_parse_format::Count;
2020
use std::borrow::Cow;
2121
use std::collections::hash_map::Entry;
2222

@@ -985,20 +985,19 @@ fn lint_named_arguments_used_positionally(
985985
}
986986
_ => {}
987987
};
988-
match a.format {
989-
FormatSpec { width: Count::CountIsName(s, _), .. }
990-
| FormatSpec { precision: Count::CountIsName(s, _), .. } => {
991-
used_argument_names.insert(s);
992-
}
993-
_ => {}
994-
};
988+
if let Count::CountIsName(s, _) = a.format.width {
989+
used_argument_names.insert(s);
990+
}
991+
if let Count::CountIsName(s, _) = a.format.precision {
992+
used_argument_names.insert(s);
993+
}
995994
}
996995
}
997996

998997
for (symbol, (index, span)) in names {
999998
if !used_argument_names.contains(symbol.as_str()) {
1000999
let msg = format!("named argument `{}` is not used by name", symbol.as_str());
1001-
let arg_span = cx.arg_spans[index];
1000+
let arg_span = cx.arg_spans.get(index).copied().unwrap_or(span);
10021001
cx.ecx.buffered_early_lint.push(BufferedEarlyLint {
10031002
span: MultiSpan::from_span(span),
10041003
msg: msg.clone(),

src/test/ui/macros/issue-99261.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
#![deny(named_arguments_used_positionally)]
4+
5+
fn main() {
6+
let value: f64 = 314.15926;
7+
let digits_before_decimal = 1;
8+
let digits_after_decimal = 2;
9+
let width = digits_before_decimal + 1 + digits_after_decimal;
10+
11+
println!(
12+
"{value:0>width$.digits_after_decimal$}",
13+
value = value,
14+
width = width,
15+
digits_after_decimal = digits_after_decimal,
16+
);
17+
}

0 commit comments

Comments
 (0)