Skip to content

Commit

Permalink
Fix span calculation on secondary_label as well
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 9, 2021
1 parent e2116ac commit 99bd24e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,9 @@ pub fn expand_preparsed_format_args(
e.note(&note);
}
if let Some((label, span)) = err.secondary_label {
let sp = fmt_span.from_inner(span);
e.span_label(sp, label);
if efmt_kind_is_lit {
e.span_label(fmt_span.from_inner(span), label);
}
}
e.emit();
return DummyResult::raw_expr(sp, true);
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/fmt/issue-91556.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let _ = format!(concat!("{0}π–³π–Ύπ—Œπ—{"), i);
//~^ ERROR: invalid format string: expected `'}'` but string was terminated
//~| NOTE: if you intended to print `{`, you can escape it using `{{`
//~| NOTE: in this expansion of concat!
//~| NOTE: in this expansion of concat!
//~| NOTE: expected `'}'` in format string
}
11 changes: 11 additions & 0 deletions src/test/ui/fmt/issue-91556.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: invalid format string: expected `'}'` but string was terminated
--> $DIR/issue-91556.rs:2:19
|
LL | let _ = format!(concat!("{0}π–³π–Ύπ—Œπ—{"), i);
| ^^^^^^^^^^^^^^^^^^^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

0 comments on commit 99bd24e

Please sign in to comment.