-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Reversed order of ?#
in format string gives unhelpful error message
#129966
Comments
Hello, It would be my first contribution to the rust compiler so it would be nice to know, if this would be feasible as a first issue. Cheers! |
Hi @grimmfl, thanks for your interest in contributing to Rust! Yes, this looks like a good first issue and the diagnostic should be reasonably easy to add. The parser for format strings is located in Also, if you haven't already, check out the rustc dev guide, especially the chapters on building/running/testing the compiler and adding new tests. And if you have any questions, don't hesitate to ask me or anyone else here or on the zulip chat. |
Thanks for your guidance. I will look into it :) |
Hi @grimmfl, are you still working on this? |
@lukas-code i would like to work on this. Can you please assign to me if it is still available. |
You can assign yourself by commenting |
@rustbot claim |
I've started looking into the code, and it is going to be my first issue in the Rust repo, so please bear with me here :) My understanding is that when parsing the formatted string parser will go into Could you guide me here? I don't think in Parser there exists a |
Generally, our error recovery works by eagerly consuming tokens in places where they are not allowed, emitting an error, and then continuing as if the user had written the correct thing.
That's what I would do. After consuming the rust/compiler/rustc_parse_format/src/lib.rs Lines 718 to 734 in f2becdf
you can try consuming # (and possibly also X after ? and other similar mistakes) and emit an error when the token was consumed successfully. You can look at suggest_format_debug or the recovery for r#ident in position for inspiration. But please try to keep the "error path" in a separate method if possible, even if position doesn't do that.
|
PR #131004 |
@rustbot claim |
…p-message, r=estebank add suggestion for wrongly ordered format parameters Add suggestion for wrongly ordered format parameters like `?#`. Supersedes rust-lang#131004 Fix rust-lang#129966
Rollup merge of rust-lang#134877 - DavisRayM:129966-format-string-help-message, r=estebank add suggestion for wrongly ordered format parameters Add suggestion for wrongly ordered format parameters like `?#`. Supersedes rust-lang#131004 Fix rust-lang#129966
Code
Current output
Desired output
Rationale and extra context
It would be helpful to point out to the user that the format parameter should be written the other way.
Other cases
No response
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: