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 interprets closing brace as fill and suggesting to add another closing brace for no apperant reason. #112732

Closed
PizzasBear opened this issue Jun 17, 2023 · 0 comments · Fixed by #113774
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@PizzasBear
Copy link
Contributor

Code

fn main() {
    println!("Hello, world! {0:}<3", 2);
}

Current output

Compiling playground v0.0.1 (/playground)
error: invalid format string: expected `'}'` but string was terminated
 --> src/main.rs:2:35
  |
2 |     println!("Hello, world! {0:}<3", 2);
  |                             -     ^ expected `'}'` in format string
  |                             |
  |                             because of this opening brace
  |
  = note: if you intended to print `{`, you can escape it using `{{`

error: could not compile `playground` (bin "playground") due to previous error

Desired output

The error should mention that the closing curly brace `}` is interpreted as the fill character and suggest the removal of the colon to fix the issue.

Rationale and extra context

The format spec allows fill to be any character including }, this may be confusing.

Other cases

No response

Anything else?

No response

@PizzasBear PizzasBear added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2023
@TaKO8Ki TaKO8Ki self-assigned this Jun 18, 2023
@bors bors closed this as completed in 444ac1a Jul 19, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants