Skip to content

Commit

Permalink
Add diagnostic width span when '0$' is used as width.
Browse files Browse the repository at this point in the history
  • Loading branch information
miam-miam committed Jul 20, 2022
1 parent 29c5a02 commit 62187b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,10 @@ impl<'a> Parser<'a> {
// '0' flag and then an ill-formatted format string with just a '$'
// and no count, but this is better if we instead interpret this as
// no '0' flag and '0$' as the width instead.
if self.consume('$') {
if let Some(end) = self.consume_pos('$') {
spec.width = CountIsParam(0);
havewidth = true;
spec.width_span = Some(self.to_span_index(end - 1).to(self.to_span_index(end + 1)));
} else {
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_parse_format/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ fn format_counts() {
},
})],
);
same(
"{1:0$.10x}",
&[NextArgument(Argument {
position: ArgumentIs(1),
format: FormatSpec {
fill: None,
align: AlignUnknown,
flags: 0,
precision: CountIs(10),
width: CountIsParam(0),
precision_span: None,
width_span: Some(InnerSpan::new(4, 6)),
ty: "x",
ty_span: None,
},
})],
);
same(
"{:.*x}",
&[NextArgument(Argument {
Expand Down

0 comments on commit 62187b1

Please sign in to comment.