mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #83348 - osa1:issue83344, r=jackh726
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 --- r? ```@estebank```
This commit is contained in:
commit
973fb4b77f
@ -213,11 +213,13 @@ impl<'a> Iterator for Parser<'a> {
|
||||
Some(String(self.string(pos + 1)))
|
||||
} else {
|
||||
let arg = self.argument();
|
||||
if let Some(end) = self.must_consume('}') {
|
||||
let start = self.to_span_index(pos);
|
||||
let end = self.to_span_index(end + 1);
|
||||
if let Some(rbrace_byte_idx) = self.must_consume('}') {
|
||||
let lbrace_inner_offset = self.to_span_index(pos);
|
||||
let rbrace_inner_offset = self.to_span_index(rbrace_byte_idx);
|
||||
if self.is_literal {
|
||||
self.arg_places.push(start.to(end));
|
||||
self.arg_places.push(
|
||||
lbrace_inner_offset.to(InnerOffset(rbrace_inner_offset.0 + 1)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Some(NextArgument(arg))
|
||||
|
6
src/test/ui/macros/issue-83344.rs
Normal file
6
src/test/ui/macros/issue-83344.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// check-fail
|
||||
|
||||
fn main() {
|
||||
println!("{}\
|
||||
"); //~^ ERROR: 1 positional argument in format string, but no arguments were given
|
||||
}
|
8
src/test/ui/macros/issue-83344.stderr
Normal file
8
src/test/ui/macros/issue-83344.stderr
Normal 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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user