Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect format string span when specifier is followed by backslash #83344

Closed
osa1 opened this issue Mar 21, 2021 · 1 comment · Fixed by #83348
Closed

Incorrect format string span when specifier is followed by backslash #83344

osa1 opened this issue Mar 21, 2021 · 1 comment · Fixed by #83348
Assignees

Comments

@osa1
Copy link
Contributor

osa1 commented Mar 21, 2021

Discovered this while debugging #83340. Repro:

fn main() {
    println!("{}\
");
}

Current output:

 --> test.rs:2:15
  |
2 |       println!("{}\
  |  _______________^
3 | | ");
  | |_

I think the span for {} is wrong. With the correct span the error would look like:

error: 1 positional argument in format string, but no arguments were given
 --> test.rs:2:15
  |
2 |       println!("{}\
  |                 ^^
3 | ");

The span is correct when {} is followed by any other character:

fn main() {
    println!("{}
");
}

Output:

error: 1 positional argument in format string, but no arguments were given
 --> test.rs:2:15
  |
2 |     println!("{}
  |               ^^

error: aborting due to previous error
@osa1
Copy link
Contributor Author

osa1 commented Mar 21, 2021

@rustbot claim

osa1 added a commit to osa1/rust that referenced this issue Mar 21, 2021
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 rust-lang#83344
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 26, 2021
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 rust-lang#83344

---

r? `@estebank`
JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 27, 2021
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 rust-lang#83344

---

r? ``@estebank``
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 27, 2021
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 rust-lang#83344

---

r? `@estebank`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 27, 2021
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 rust-lang#83344

---

r? ``@estebank``
JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 27, 2021
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 rust-lang#83344

---

r? ```@estebank```
@bors bors closed this as completed in 5b9bac2 Mar 27, 2021
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 8, 2021
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 rust-lang#83344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant