Skip to content

Commit 1b044da

Browse files
committed
Separate CountIsStar from CountIsParam in rustc_parse_format.
1 parent 4d45b07 commit 1b044da

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

compiler/rustc_builtin_macros/src/format.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<'a, 'b> Context<'a, 'b> {
541541
) {
542542
match c {
543543
parse::CountImplied | parse::CountIs(..) => {}
544-
parse::CountIsParam(i) => {
544+
parse::CountIsParam(i) | parse::CountIsStar(i) => {
545545
self.unused_names_lint.maybe_add_positional_named_arg(
546546
self.args.get(i),
547547
named_arg_type,
@@ -589,7 +589,7 @@ impl<'a, 'b> Context<'a, 'b> {
589589
+ self
590590
.arg_with_formatting
591591
.iter()
592-
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
592+
.filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
593593
.count();
594594
if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
595595
e = self.ecx.struct_span_err(
@@ -639,7 +639,7 @@ impl<'a, 'b> Context<'a, 'b> {
639639
if let Some(span) = fmt.precision_span {
640640
let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
641641
match fmt.precision {
642-
parse::CountIsParam(pos) if pos > self.num_args() => {
642+
parse::CountIsParam(pos) if pos >= self.num_args() => {
643643
e.span_label(
644644
span,
645645
&format!(
@@ -651,12 +651,12 @@ impl<'a, 'b> Context<'a, 'b> {
651651
);
652652
zero_based_note = true;
653653
}
654-
parse::CountIsParam(pos) => {
654+
parse::CountIsStar(pos) => {
655655
let count = self.pieces.len()
656656
+ self
657657
.arg_with_formatting
658658
.iter()
659-
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
659+
.filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
660660
.count();
661661
e.span_label(
662662
span,
@@ -837,7 +837,7 @@ impl<'a, 'b> Context<'a, 'b> {
837837
};
838838
match c {
839839
parse::CountIs(i) => count(sym::Is, Some(self.ecx.expr_usize(sp, i))),
840-
parse::CountIsParam(i) => {
840+
parse::CountIsParam(i) | parse::CountIsStar(i) => {
841841
// This needs mapping too, as `i` is referring to a macro
842842
// argument. If `i` is not found in `count_positions` then
843843
// the error had already been emitted elsewhere.

compiler/rustc_parse_format/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ pub enum Count<'a> {
167167
CountIsName(&'a str, InnerSpan),
168168
/// The count is specified by the argument at the given index.
169169
CountIsParam(usize),
170+
/// The count is specified by a star (like in `{:.*}`) that refers to the argument at the given index.
171+
CountIsStar(usize),
170172
/// The count is implied and cannot be explicitly specified.
171173
CountImplied,
172174
}
@@ -618,7 +620,7 @@ impl<'a> Parser<'a> {
618620
// We can do this immediately as `position` is resolved later.
619621
let i = self.curarg;
620622
self.curarg += 1;
621-
spec.precision = CountIsParam(i);
623+
spec.precision = CountIsStar(i);
622624
} else {
623625
spec.precision = self.count(start + 1);
624626
}

compiler/rustc_parse_format/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn format_counts() {
244244
fill: None,
245245
align: AlignUnknown,
246246
flags: 0,
247-
precision: CountIsParam(0),
247+
precision: CountIsStar(0),
248248
precision_span: Some(InnerSpan { start: 3, end: 5 }),
249249
width: CountImplied,
250250
width_span: None,

0 commit comments

Comments
 (0)