Skip to content

Commit 6ec2bcb

Browse files
authored
Rollup merge of rust-lang#91575 - compiler-errors:issue-91556, r=cjgillot
Fix ICE on format string of macro with secondary-label This generalizes the fix rust-lang#86104 to also correctly skip `Span::from_inner` for the `secondary_label` of a format macro parsing error as well. We can alternatively skip the `span_label` diagnostic call for the secondary label as well, since that label probably only makes sense when the _proper_ span is computed. Fixes rust-lang#91556
2 parents f758c82 + 99bd24e commit 6ec2bcb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compiler/rustc_builtin_macros/src/format.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,9 @@ pub fn expand_preparsed_format_args(
995995
e.note(&note);
996996
}
997997
if let Some((label, span)) = err.secondary_label {
998-
let sp = fmt_span.from_inner(span);
999-
e.span_label(sp, label);
998+
if efmt_kind_is_lit {
999+
e.span_label(fmt_span.from_inner(span), label);
1000+
}
10001001
}
10011002
e.emit();
10021003
return DummyResult::raw_expr(sp, true);

src/test/ui/fmt/issue-91556.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let _ = format!(concat!("{0}𝖳𝖾𝗌𝗍{"), i);
3+
//~^ ERROR: invalid format string: expected `'}'` but string was terminated
4+
//~| NOTE: if you intended to print `{`, you can escape it using `{{`
5+
//~| NOTE: in this expansion of concat!
6+
//~| NOTE: in this expansion of concat!
7+
//~| NOTE: expected `'}'` in format string
8+
}

src/test/ui/fmt/issue-91556.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: invalid format string: expected `'}'` but string was terminated
2+
--> $DIR/issue-91556.rs:2:19
3+
|
4+
LL | let _ = format!(concat!("{0}𝖳𝖾𝗌𝗍{"), i);
5+
| ^^^^^^^^^^^^^^^^^^^ expected `'}'` in format string
6+
|
7+
= note: if you intended to print `{`, you can escape it using `{{`
8+
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)