-
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
Hint on missing tuple parens in pattern #63962
Comments
I think the right approach here would be to check if the scrutinee type (expected type in this context) has a single field of a tuple type with as many fields as the tuple struct pattern has. Place to change: rust/src/librustc_typeck/check/pat.rs Lines 678 to 688 in 53df91a
If you tackle this, first please also refactor the snippet highlighted above into a diagnostics-only method and then do your changes in there. |
Can I pick up this one? Doesn't look like anybody working on this. |
Maybe I misunderstood it, or am missing something here |
This #64161 seems to have changed some things here. Is this issue still relevant? |
cc @estebank Ostensibly it is still relevant as we could emit a specific suggestion in this case. |
Yes, that PR only adds a bit of context that should generally be useful, but this is about adding a structured suggestion for this case in particular. This is more focused and more useful for this case in particular :) Looking forward to it! |
Thanks @Centril @estebank. I have one more question though, rust/src/librustc_typeck/check/pat.rs Lines 686 to 709 in 24d0a01
This The condition to show a missing parenthesis message should be something like:
But fields[0] is not a vector and I cannot seem to figure out how to find the number of elements in the expected type |
You'll need to look at |
Fixes rust-lang#63962. Hint about missing tuple parentheses in patterns
Rollup of 9 pull requests Successful merges: - #63907 (Add explanation to type mismatch involving type params and assoc types) - #64615 (rustbuild: Turn down compression on exe installers) - #64617 (rustbuild: Turn down compression on msi installers) - #64618 (rustbuild: Improve output of `dist` step) - #64619 (Fixes #63962. Hint about missing tuple parentheses in patterns) - #64634 (Update to LLVM 9.0.0) - #64635 (Allow using fn pointers in const fn with unleash miri) - #64660 (unify errors for tuple/struct variants) - #64664 (fully remove AstBuilder) Failed merges: r? @ghost
It'd be nice to smartly hint about missing tuple parentheses in patterns, especially in positions where parentheses nesting is required.
Example of incorrect code:
The error:
This error is confusing, especially since
Some
is a "tuple pattern" which is confusable with its tuple field. An error that suggests missing tuple parentheses would be helpful.This issue has been assigned to @sam09 via this comment.
The text was updated successfully, but these errors were encountered: