-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Tuple struct patterns can match unit structs #28692
Comments
/cc @rust-lang/lang This kind of makes sense because |
The problem is that "kinds" of structs are different, |
I think there was a recent RFC touching this. |
You can't match |
To be honest, I don't see why |
You will get an |
@arielb1 I know it doesn't work, but I don't see why it couldn't be made to work. |
@durka see rust-lang/rfcs#218 ; in particular https://github.com/rust-lang/rfcs/blob/master/text/0218-empty-struct-with-braces.md#empty-tuple-structs ; we are allowing unit and braced structs to mix in ways that we do not want to allow tuple structs to mix as well. |
Regarding the ability of |
This patch uses the same data structures for structs and enum variants in AST and HIR. These changes in data structures lead to noticeable simplification in most of code dealing with them. I didn't touch the top level, i.e. `ItemStruct` is still `ItemStruct` and not `ItemEnum` with one variant, like in the type checker. As part of this patch, structures and variants get the `kind` field making distinction between "normal" structs, tuple structs and unit structs explicit instead of relying on the number of fields and presence of constructor `NodeId`. In particular, we can now distinguish empty tuple structs from unit structs, which was impossible before! Comprehensive tests for empty structs are added and some improvements to empty struct feature gates are made. Some tests don't pass due to issue #28692 , they are still there for completeness, but are commented out. This patch fixes issue mentioned in #16819 (comment), now emptiness of tuple structs is checked after expansion. It also touches #28750 by providing span for visit_struct_def cc #28336 r? @nrc
@nikomatsakis |
Fixes #28692 Fixes #28992 Fixes some other similar issues (see the tests) [breaking-change], needs crater run (cc @brson or @alexcrichton ) The pattern with parens `UnitVariant(..)` for unit variants seems to be popular in rustc (see the second commit), but mostly used by one person (@nikomatsakis), according to git blame. If it causes breakage on crates.io I'll add an exceptional case for it.
Fixes rust-lang/rust#28692 Fixes rust-lang/rust#28992 Fixes some other similar issues (see the tests) [breaking-change], needs crater run (cc @brson or @alexcrichton ) The pattern with parens `UnitVariant(..)` for unit variants seems to be popular in rustc (see the second commit), but mostly used by one person (@nikomatsakis), according to git blame. If it causes breakage on crates.io I'll add an exceptional case for it.
This compiles on stable and nightly, but it shouldn't:
The text was updated successfully, but these errors were encountered: