Skip to content

fmt family macros should report better error for "{"  #34300

Closed
@pnkfelix

Description

@pnkfelix

During tutorial, a student wanted to print out a { in the std output.

Their intuitive way of doing this yielded a non-ideal error message:

fn main() {
    println!("{");
}

Error message:

error: invalid format string: expected `'}'` but string was terminated
 --> <std macros>:1:33
1 |> ( $ fmt : expr ) => ( print ! ( concat ! ( $ fmt , "\n" ) ) ) ; (
  |>                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
<std macros>:1:33: 1:58: note: in this expansion of concat!
<std macros>:1:33: 1:58: note: in this expansion of format_args!
<std macros>:1:33: 1:58: note: in this expansion of print! (defined in <std macros>)
<std macros>:1:33: 1:58: note: in this expansion of println! (defined in <std macros>)

error: aborting due to previous error

The student knew that they wanted some kind of escape sequence, but did not know what to use (e.g. they tried e.g. \{, which does not work).

Ideally we would include a HELP output that would suggest that if an output { were desired, then one should instead write {{.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions