format macro argument parsing fix

When the character next to `{}` is "shifted" (when mapping a byte index
in the format string to span) we should avoid shifting the span end
index, so first map the index of `}` to span, then bump the span,
instead of first mapping the next byte index to a span (which causes
bumping the end span too much).

Regression test added.

Fixes #83344
This commit is contained in:
Ömer Sinan Ağacan 2021-03-21 17:29:21 +03:00
parent f811f14006
commit 5b9bac2ab6
4 changed files with 23 additions and 6 deletions

View file

@ -0,0 +1,6 @@
// check-fail
fn main() {
println!("{}\
"); //~^ ERROR: 1 positional argument in format string, but no arguments were given
}

View file

@ -0,0 +1,8 @@
error: 1 positional argument in format string, but no arguments were given
--> $DIR/issue-83344.rs:4:15
|
LL | println!("{}\
| ^^
error: aborting due to previous error

View file

@ -75,8 +75,9 @@ LL | "1", "2", "3",
|
help: try this
|
LL | "some 1{} / {}", "2", "3",
| ^ --
LL | "some 1/
LL | {} / {}", "2", "3",
|
error: literal with an empty format string
--> $DIR/write_literal_2.rs:25:14