Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format! parse error expectations are sometimes inaccurate #57277

Closed
euclio opened this issue Jan 2, 2019 · 0 comments · Fixed by #64080
Closed

format! parse error expectations are sometimes inaccurate #57277

euclio opened this issue Jan 2, 2019 · 0 comments · Fixed by #64080
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST.

Comments

@euclio
Copy link
Contributor

euclio commented Jan 2, 2019

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
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. labels Jan 2, 2019
@bors bors closed this as completed in 4576668 Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants