Separate CountIsStar from CountIsParam in rustc_parse_format.
This commit is contained in:
parent
4d45b0745a
commit
1b044da5bb
3 changed files with 10 additions and 8 deletions
|
@ -541,7 +541,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
) {
|
) {
|
||||||
match c {
|
match c {
|
||||||
parse::CountImplied | parse::CountIs(..) => {}
|
parse::CountImplied | parse::CountIs(..) => {}
|
||||||
parse::CountIsParam(i) => {
|
parse::CountIsParam(i) | parse::CountIsStar(i) => {
|
||||||
self.unused_names_lint.maybe_add_positional_named_arg(
|
self.unused_names_lint.maybe_add_positional_named_arg(
|
||||||
self.args.get(i),
|
self.args.get(i),
|
||||||
named_arg_type,
|
named_arg_type,
|
||||||
|
@ -589,7 +589,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
+ self
|
+ self
|
||||||
.arg_with_formatting
|
.arg_with_formatting
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
|
.filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
|
||||||
.count();
|
.count();
|
||||||
if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
|
if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
|
||||||
e = self.ecx.struct_span_err(
|
e = self.ecx.struct_span_err(
|
||||||
|
@ -639,7 +639,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
if let Some(span) = fmt.precision_span {
|
if let Some(span) = fmt.precision_span {
|
||||||
let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
|
let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
|
||||||
match fmt.precision {
|
match fmt.precision {
|
||||||
parse::CountIsParam(pos) if pos > self.num_args() => {
|
parse::CountIsParam(pos) if pos >= self.num_args() => {
|
||||||
e.span_label(
|
e.span_label(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
|
@ -651,12 +651,12 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
);
|
);
|
||||||
zero_based_note = true;
|
zero_based_note = true;
|
||||||
}
|
}
|
||||||
parse::CountIsParam(pos) => {
|
parse::CountIsStar(pos) => {
|
||||||
let count = self.pieces.len()
|
let count = self.pieces.len()
|
||||||
+ self
|
+ self
|
||||||
.arg_with_formatting
|
.arg_with_formatting
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
|
.filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
|
||||||
.count();
|
.count();
|
||||||
e.span_label(
|
e.span_label(
|
||||||
span,
|
span,
|
||||||
|
@ -837,7 +837,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
};
|
};
|
||||||
match c {
|
match c {
|
||||||
parse::CountIs(i) => count(sym::Is, Some(self.ecx.expr_usize(sp, i))),
|
parse::CountIs(i) => count(sym::Is, Some(self.ecx.expr_usize(sp, i))),
|
||||||
parse::CountIsParam(i) => {
|
parse::CountIsParam(i) | parse::CountIsStar(i) => {
|
||||||
// This needs mapping too, as `i` is referring to a macro
|
// This needs mapping too, as `i` is referring to a macro
|
||||||
// argument. If `i` is not found in `count_positions` then
|
// argument. If `i` is not found in `count_positions` then
|
||||||
// the error had already been emitted elsewhere.
|
// the error had already been emitted elsewhere.
|
||||||
|
|
|
@ -167,6 +167,8 @@ pub enum Count<'a> {
|
||||||
CountIsName(&'a str, InnerSpan),
|
CountIsName(&'a str, InnerSpan),
|
||||||
/// The count is specified by the argument at the given index.
|
/// The count is specified by the argument at the given index.
|
||||||
CountIsParam(usize),
|
CountIsParam(usize),
|
||||||
|
/// The count is specified by a star (like in `{:.*}`) that refers to the argument at the given index.
|
||||||
|
CountIsStar(usize),
|
||||||
/// The count is implied and cannot be explicitly specified.
|
/// The count is implied and cannot be explicitly specified.
|
||||||
CountImplied,
|
CountImplied,
|
||||||
}
|
}
|
||||||
|
@ -618,7 +620,7 @@ impl<'a> Parser<'a> {
|
||||||
// We can do this immediately as `position` is resolved later.
|
// We can do this immediately as `position` is resolved later.
|
||||||
let i = self.curarg;
|
let i = self.curarg;
|
||||||
self.curarg += 1;
|
self.curarg += 1;
|
||||||
spec.precision = CountIsParam(i);
|
spec.precision = CountIsStar(i);
|
||||||
} else {
|
} else {
|
||||||
spec.precision = self.count(start + 1);
|
spec.precision = self.count(start + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ fn format_counts() {
|
||||||
fill: None,
|
fill: None,
|
||||||
align: AlignUnknown,
|
align: AlignUnknown,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
precision: CountIsParam(0),
|
precision: CountIsStar(0),
|
||||||
precision_span: Some(InnerSpan { start: 3, end: 5 }),
|
precision_span: Some(InnerSpan { start: 3, end: 5 }),
|
||||||
width: CountImplied,
|
width: CountImplied,
|
||||||
width_span: None,
|
width_span: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue