Skip to content

format! parse error expectations are sometimes inaccurate #57277

Description

@euclio

See #56897 (comment).

The format! macro claims that it expects , when failing to parse a format string argument, but it actually accepts all tokens that make up expressions in that position. The simplest fix would be to use expect(&token::Comma), but that causes parsing errors directly after the format string to claim that expression tokens are expected in that position are accepted, when they are not.

In other words, it would be nice to get diagnostics like this:

-error: expected token: `,`
+error: expected one of `,`, `.`, `?`, or an operator, found `1`
   --> $DIR/bad-format-args.rs:4:19
    |
 LL |     format!("", 1 1); //~ ERROR expected token: `,`
-   |                   ^
+   |                   ^ expected one of `,`, `.`, `?`, or an operator here

while avoiding getting diagnostics like this:

-error: expected token: `,`
+error: expected one of `,`, `.`, `?`, or an operator, found `1`
   --> $DIR/bad-format-args.rs:3:16
    |
 LL |     format!("" 1); //~ ERROR expected token: `,`
-   |                ^
+   |                ^ expected one of `,`, `.`, `?`, or an operator here

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions