about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-08-29 16:49:45 +0530
committerGitHub <noreply@github.com>2022-08-29 16:49:45 +0530
commit0b6faca67057ceb99ee3af342d4ba6f1ac407fde (patch)
tree2ca8afd1a123f358dc5938f8305289ec24add362 /compiler/rustc_builtin_macros/src
parent141728fc61254fafe14dbe8387ec08c5ecc046a9 (diff)
parentaebad394142aba6f5dc11a1fad5731e12c351c00 (diff)
downloadrust-0b6faca67057ceb99ee3af342d4ba6f1ac407fde.tar.gz
rust-0b6faca67057ceb99ee3af342d4ba6f1ac407fde.zip
Rollup merge of #101000 - m-ou-se:count-is-star, r=nagisa
Separate CountIsStar from CountIsParam in rustc_parse_format.

`rustc_parse_format`'s parser would result in the exact same output for `{:.*}` and `{:.0$}`, making it hard for diagnostics to handle these cases properly.

This splits those cases by adding a new `CountIsStar` enum variant.

This fixes #100995

Prerequisite for https://github.com/rust-lang/rust/pull/100996
Diffstat (limited to 'compiler/rustc_builtin_macros/src')
-rw-r--r--compiler/rustc_builtin_macros/src/format.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs
index 2816f81fef1..21004871075 100644
--- a/compiler/rustc_builtin_macros/src/format.rs
+++ b/compiler/rustc_builtin_macros/src/format.rs
@@ -541,7 +541,7 @@ impl<'a, 'b> Context<'a, 'b> {
     ) {
         match c {
             parse::CountImplied | parse::CountIs(..) => {}
-            parse::CountIsParam(i) => {
+            parse::CountIsParam(i) | parse::CountIsStar(i) => {
                 self.unused_names_lint.maybe_add_positional_named_arg(
                     self.args.get(i),
                     named_arg_type,
@@ -589,7 +589,7 @@ impl<'a, 'b> Context<'a, 'b> {
             + self
                 .arg_with_formatting
                 .iter()
-                .filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
+                .filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
                 .count();
         if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
             e = self.ecx.struct_span_err(
@@ -639,7 +639,7 @@ impl<'a, 'b> Context<'a, 'b> {
             if let Some(span) = fmt.precision_span {
                 let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
                 match fmt.precision {
-                    parse::CountIsParam(pos) if pos > self.num_args() => {
+                    parse::CountIsParam(pos) if pos >= self.num_args() => {
                         e.span_label(
                             span,
                             &format!(
@@ -651,12 +651,12 @@ impl<'a, 'b> Context<'a, 'b> {
                         );
                         zero_based_note = true;
                     }
-                    parse::CountIsParam(pos) => {
+                    parse::CountIsStar(pos) => {
                         let count = self.pieces.len()
                             + self
                                 .arg_with_formatting
                                 .iter()
-                                .filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
+                                .filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
                                 .count();
                         e.span_label(
                             span,
@@ -837,7 +837,7 @@ impl<'a, 'b> Context<'a, 'b> {
         };
         match c {
             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
                 // argument. If `i` is not found in `count_positions` then
                 // the error had already been emitted elsewhere.