-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for RFC 2338, "Type alias enum variants" #49683
Comments
I'd like to try implementing this. Since there was a previous implementation attempt in #31179, I can probably start off of that, but mentoring instructions would be quite welcome. |
Short instructions:
|
I have a specific concern on this. Right now, every concrete type name contains information of its component type names, making it very easy to have the name length being explode. Introducing something that making this issue worse may not be a good idea if we haven't get the type names shorted. Here is an example of how bad this problem can be. Internally, a type should contain all information to identify itself. But it is not necessary appear in the name, especially when the name is too long, because type names areintended to be read by human, and no one will read a name with a million chars. On the other hand, computer code will feel more comfortable to manipulating referencing structures. So by limiting the type name size we wouldn't lose anything. To making things worse, I just figured out that the length of a single type is not the issue I experienced. The problem is that there are too many (and too long) type names being generated, and so exceeded the compiler limit. This is why it is getting worse when I extract methods as it forces the compiler to generate more types. This RFC, once implemented, will add much more types to the system, so please measure a typical closure-heavy-and-impl-trait-heavy program, to see how bad this problem is. It would also be good to allow the compiler to generate statistics of the types it generates, so we can keep tracking this. |
@djc Did you manage to make any headway on the implementation of this? |
@alexreg no, not yet. Feel free to move forward if you want to take a crack at it! |
Too busy right now, I'm afraid. I'd need more detailed mentoring instructions too, as too many of these concepts are foreign to me... best someone else tackles it. |
It was already implemented. Why not to reopen the previous PR? |
@pravic Where’s that PR? |
Thanks. |
Is there anyone currently working on this? I would love to see this RFC implemented. If there were mentoring instructions available I would take a stab at it. |
@tlively Do you feel you need something more detailed than |
@tlively I'm currently not working on this. Between the stuff that @petrochenkov already wrote here and the earlier implementation attempt I linked from the second comment, I think you should probably have a good starting point to dig in? |
Ok, I think I should be able to figure it out. I'll be trying this out over the next few days. Thanks, everyone! |
@tlively Glad to hear! Let us know how you get on. |
@alexreg So far it's slow-going, but I'm still chipping away at it! |
@tlively Okay. If you need any help, pop into Discord. Even I may be able to assist you a bit with it. |
I was about to open an enhancement request to support code like:
|
Any updates on this lately, @tlively? :-) |
No, I wasn’t able to make meaningful progress and I haven’t looked at it in a while. If someone else wants to take a look they should go for it. |
Should this really mention type aliases at all? |
I still think we should reconsider and not implement the "argument transfer" scheme |
So for some reason this nightly feature is required when implementing the following macro (found in nvzqz/static-assertions#11): macro_rules! assert_variant {
($e:ty, $v:ident) => {
const _: fn($e) -> () = |e| match e {
<$e>::$v => {},
_ => {},
};
}
} Does anyone have an idea as to why? |
@nvzqz The stable solution will look something like: macro_rules! assert_variant {
($e:ident, $v:ident) => {
const _: fn($e) -> () = |e| match e {
$e::$v => {},
_ => {},
};
}
} or macro_rules! assert_variant {
($e:path, $v:ident) => {
const _: fn($e) -> () = {
use $e as my_ident; // On 2018 edition, or if `$e` is guaranteed to be a crate-relative path
|e| match e {
my_ident::$v => {},
_ => {},
}
};
}
} (See also #48067 that would provide a better solution for the second case.) |
So the issue with using |
Once this is stabilized, we can close #52118 if it hasn't been closed earlier by adding a suggestion to use the enum's path instead of |
We discussed this on the language team meeting today and gave the green light for a stabilization report which I (@Centril) will write. |
I should be able to stabilise this if I'm not too busy with other things at the time. (Or @Centril is welcome to after writing the report.) |
I will do both things at the same time... :) |
type_alias_enum_variants: fix #61801; allow a path pattern to infer Fix #61801. Given a type-relative path pattern referring to an enum variant through a type alias, allow inferring the generic argument applied in the expectation set by the scrutinee of a `match` expression. Similar issues may exist for `let` statements but I don't know how to test for that since `PhantomData<T>` is necessary...) The gist of the problem here was that `resolve_ty_and_res_ufcs` was called twice which is apparently no good... It is possible that this PR is papering over some deeper problem, but that is beyond my knowledge of the compiler. r? @petrochenkov cc @eddyb @alexreg cc #61682 cc #49683
type_alias_enum_variants: fix rust-lang#61801; allow a path pattern to infer Fix rust-lang#61801. Given a type-relative path pattern referring to an enum variant through a type alias, allow inferring the generic argument applied in the expectation set by the scrutinee of a `match` expression. Similar issues may exist for `let` statements but I don't know how to test for that since `PhantomData<T>` is necessary...) The gist of the problem here was that `resolve_ty_and_res_ufcs` was called twice which is apparently no good... It is possible that this PR is papering over some deeper problem, but that is beyond my knowledge of the compiler. r? @petrochenkov cc @eddyb @alexreg cc rust-lang#61682 cc rust-lang#49683
type_alias_enum_variants: fix rust-lang#61801; allow a path pattern to infer Fix rust-lang#61801. Given a type-relative path pattern referring to an enum variant through a type alias, allow inferring the generic argument applied in the expectation set by the scrutinee of a `match` expression. Similar issues may exist for `let` statements but I don't know how to test for that since `PhantomData<T>` is necessary...) The gist of the problem here was that `resolve_ty_and_res_ufcs` was called twice which is apparently no good... It is possible that this PR is papering over some deeper problem, but that is beyond my knowledge of the compiler. r? @petrochenkov cc @eddyb @alexreg cc rust-lang#61682 cc rust-lang#49683
type_alias_enum_variants: fix rust-lang#61801; allow a path pattern to infer Fix rust-lang#61801. Given a type-relative path pattern referring to an enum variant through a type alias, allow inferring the generic argument applied in the expectation set by the scrutinee of a `match` expression. Similar issues may exist for `let` statements but I don't know how to test for that since `PhantomData<T>` is necessary...) The gist of the problem here was that `resolve_ty_and_res_ufcs` was called twice which is apparently no good... It is possible that this PR is papering over some deeper problem, but that is beyond my knowledge of the compiler. r? @petrochenkov cc @eddyb @alexreg cc rust-lang#61682 cc rust-lang#49683
type_alias_enum_variants: fix rust-lang#61801; allow a path pattern to infer Fix rust-lang#61801. Given a type-relative path pattern referring to an enum variant through a type alias, allow inferring the generic argument applied in the expectation set by the scrutinee of a `match` expression. Similar issues may exist for `let` statements but I don't know how to test for that since `PhantomData<T>` is necessary...) The gist of the problem here was that `resolve_ty_and_res_ufcs` was called twice which is apparently no good... It is possible that this PR is papering over some deeper problem, but that is beyond my knowledge of the compiler. r? @petrochenkov cc @eddyb @alexreg cc rust-lang#61682 cc rust-lang#49683
type_alias_enum_variants: fix #61801; allow a path pattern to infer Fix #61801. Given a type-relative path pattern referring to an enum variant through a type alias, allow inferring the generic argument applied in the expectation set by the scrutinee of a `match` expression. Similar issues may exist for `let` statements but I don't know how to test for that since `PhantomData<T>` is necessary...) The gist of the problem here was that `resolve_ty_and_res_ufcs` was called twice which is apparently no good... It is possible that this PR is papering over some deeper problem, but that is beyond my knowledge of the compiler. r? @petrochenkov cc @eddyb @alexreg cc #61682 cc #49683
I have proposed stabilization in #61682. |
Stabilization has been done. Documentation issue is rust-lang/reference#631. Everything that needs to be done on rust-lang/rust is done so I'm closing this issue as a result. |
This is a tracking issue for the RFC "Type alias enum variants" (rust-lang/rfcs#2338).
Steps:
type_alias_enum_variants
in Rust 1.37.0 #61682)Unresolved questions:
The text was updated successfully, but these errors were encountered: