diff options
| author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2021-03-21 17:29:21 +0300 |
|---|---|---|
| committer | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2021-03-27 13:06:36 +0300 |
| commit | 5b9bac2ab62063229c419909f89a41890c57f78f (patch) | |
| tree | c14ccada7ceaaf8f6fd052194fb0c3a79f339f62 /compiler/rustc_parse_format | |
| parent | f811f14006fa46030f1af714f7d640580d3ad822 (diff) | |
| download | rust-5b9bac2ab62063229c419909f89a41890c57f78f.tar.gz rust-5b9bac2ab62063229c419909f89a41890c57f78f.zip | |
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
Diffstat (limited to 'compiler/rustc_parse_format')
| -rw-r--r-- | compiler/rustc_parse_format/src/lib.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index c2fc2bfcd33..bc180ff3060 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -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)) |
