Auto merge of #57140 - estebank:str-err, r=varkor
Tweaks to format string diagnostics Add label spans and fix incorrect spans. Fix #55155, fix #55350.
This commit is contained in:
@@ -860,7 +860,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||
}
|
||||
|
||||
let arg_spans = parser.arg_places.iter()
|
||||
.map(|&(start, end)| fmt.span.from_inner_byte_pos(start, end))
|
||||
.map(|&(parse::SpanIndex(start), parse::SpanIndex(end))| {
|
||||
fmt.span.from_inner_byte_pos(start, end)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut cx = Context {
|
||||
@@ -954,13 +956,18 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||
let mut diag = {
|
||||
if errs_len == 1 {
|
||||
let (sp, msg) = errs.into_iter().next().unwrap();
|
||||
cx.ecx.struct_span_err(sp, msg)
|
||||
let mut diag = cx.ecx.struct_span_err(sp, msg);
|
||||
diag.span_label(sp, msg);
|
||||
diag
|
||||
} else {
|
||||
let mut diag = cx.ecx.struct_span_err(
|
||||
errs.iter().map(|&(sp, _)| sp).collect::<Vec<Span>>(),
|
||||
"multiple unused formatting arguments",
|
||||
);
|
||||
diag.span_label(cx.fmtsp, "multiple missing formatting specifiers");
|
||||
for (sp, msg) in errs {
|
||||
diag.span_label(sp, msg);
|
||||
}
|
||||
diag
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user