Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
pnkfelix opened this issue Jun 16, 2016 · 0 comments
Closed

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

pnkfelix opened this issue Jun 16, 2016 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@pnkfelix
Copy link
Member

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 {{.

@pnkfelix pnkfelix added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 16, 2016
eddyb added a commit to eddyb/rust that referenced this issue Nov 11, 2016
…chton

On fmt string with unescaped `{` note how to escape

On cases of malformed format strings where a `{` hasn't been properly escaped, like `println!("{");`, present a NOTE explaining how to escape the `{` char.

Fix rust-lang#34300.
eddyb added a commit to eddyb/rust that referenced this issue Nov 12, 2016
…chton

On fmt string with unescaped `{` note how to escape

On cases of malformed format strings where a `{` hasn't been properly escaped, like `println!("{");`, present a NOTE explaining how to escape the `{` char.

Fix rust-lang#34300.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

1 participant