Skip to content

Format interprets closing brace as fill and suggesting to add another closing brace for no apperant reason. #112732

Closed
@PizzasBear

Description

@PizzasBear

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions