Fix ICE in named_arguments_used_positionally lint
This commit is contained in:
parent
0fe5390a88
commit
b71a09fda0
2 changed files with 25 additions and 9 deletions
|
@ -16,7 +16,7 @@ use smallvec::SmallVec;
|
||||||
|
|
||||||
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
|
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
|
||||||
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, LintId};
|
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, LintId};
|
||||||
use rustc_parse_format::{Count, FormatSpec};
|
use rustc_parse_format::Count;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
|
@ -985,20 +985,19 @@ fn lint_named_arguments_used_positionally(
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
match a.format {
|
if let Count::CountIsName(s, _) = a.format.width {
|
||||||
FormatSpec { width: Count::CountIsName(s, _), .. }
|
used_argument_names.insert(s);
|
||||||
| FormatSpec { precision: Count::CountIsName(s, _), .. } => {
|
}
|
||||||
used_argument_names.insert(s);
|
if let Count::CountIsName(s, _) = a.format.precision {
|
||||||
}
|
used_argument_names.insert(s);
|
||||||
_ => {}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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[index];
|
let arg_span = cx.arg_spans.get(index).copied().unwrap_or(span);
|
||||||
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(),
|
||||||
|
|
17
src/test/ui/macros/issue-99261.rs
Normal file
17
src/test/ui/macros/issue-99261.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![deny(named_arguments_used_positionally)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let value: f64 = 314.15926;
|
||||||
|
let digits_before_decimal = 1;
|
||||||
|
let digits_after_decimal = 2;
|
||||||
|
let width = digits_before_decimal + 1 + digits_after_decimal;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{value:0>width$.digits_after_decimal$}",
|
||||||
|
value = value,
|
||||||
|
width = width,
|
||||||
|
digits_after_decimal = digits_after_decimal,
|
||||||
|
);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue