-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Better diagnostics for '..' pattern fragment not in the last position #49268
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/test/ui/issue-49257.rs
Outdated
let p = Point { x: 0, y: 0 }; | ||
let Point { .., y } = p; //~ ERROR expected `}`, found `,` | ||
//~| ERROR pattern does not mention field `x` | ||
//~| ERROR pattern does not mention field `y` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the pattern mentions field y
actually.
Ideally we should do recovery in the parser and continue parsing fields after encountering incorrect ..
, but it requires somewhat larger refactoring of fn parse_pat_fields
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petrochenkov Would it be possible to just hide the "pattern does not metion field" errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Badel2
Yes, but in this case Pat { .., field }
or Pat { field, .., }
have a single obvious meaning, so it's better to use recovery at syntax level and starting from that assume that Pat { field, .. }
was actually implied.
@bors r+ |
📌 Commit 347b9d6 has been approved by |
@bors rollup |
…trochenkov Better diagnostics for '..' pattern fragment not in the last position Fixes rust-lang#49257.
this hit an error in the rollup: @bors r- |
347b9d6
to
3d0ccb2
Compare
rebased |
@bors r+ |
📌 Commit 3d0ccb2 has been approved by |
…trochenkov Better diagnostics for '..' pattern fragment not in the last position Fixes rust-lang#49257.
…trochenkov Better diagnostics for '..' pattern fragment not in the last position Fixes rust-lang#49257.
Accept `..` in incorrect position to avoid further errors We currently give a specific message when encountering a `..` anywhere other than the end of a pattern. Modify the parser to accept it (while still emitting the error) so that we don't also trigger "missing fields in pattern" errors afterwards. Add suggestions to either remove trailing `,` or moving the `..` to the end. Follow up to rust-lang#49268.
Accept `..` in incorrect position to avoid further errors We currently give a specific message when encountering a `..` anywhere other than the end of a pattern. Modify the parser to accept it (while still emitting the error) so that we don't also trigger "missing fields in pattern" errors afterwards. Add suggestions to either remove trailing `,` or moving the `..` to the end. Follow up to #49268.
Fixes #49257.