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

suggest {var:?} when finding {:?var} in inline format strings #106572

Closed
matthiaskrgr opened this issue Jan 7, 2023 · 1 comment · Fixed by #106805
Closed

suggest {var:?} when finding {:?var} in inline format strings #106572

matthiaskrgr opened this issue Jan 7, 2023 · 1 comment · Fixed by #106805
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

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jan 7, 2023

    eprintln!("Timings:\n{:?timer}");

The current suggestion is:

error: invalid format string: expected `'}'`, found `'t'`
   --> src/main.rs:696:29
    |
696 |     eprintln!("Timings:\n{:?timer}");
    |                          -  ^ expected `}` in format string
    |                          |
    |                          because of this opening brace
    |
    = note: if you intended to print `{`, you can escape it using `{{`

error: could not compile `icemaker` due to previous error

We could perhaps detect the formatting parameter is at the beginning of the fmt string and that it should go at the end, in order to suggest {timer:?}

@matthiaskrgr matthiaskrgr 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 Jan 7, 2023
@madsravn
Copy link
Contributor

madsravn commented Jan 7, 2023

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 3, 2023
Suggest `{var:?}` when finding `{?:var}` in inline format strings

Link to issue: rust-lang#106572

This is my first PR to this project, so hopefully I can get some good pointers with me from the first PR.

Currently my idea was to test out whether or not this is the correct solution to this issue and then hopefully expand upon the idea to not only work for Debug formatting but for all of  them. If this is a valid solution, I will create a new issue to give a better error message to a broader range of wrong-order formatting.
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
Development

Successfully merging a pull request may close this issue.

2 participants