(WIP) rustc: Implement nested C-like enums#17050
Closed
pczarn wants to merge 2 commits intorust-lang:masterfrom
Closed
(WIP) rustc: Implement nested C-like enums#17050pczarn wants to merge 2 commits intorust-lang:masterfrom
pczarn wants to merge 2 commits intorust-lang:masterfrom
Conversation
Contributor
|
I wonder if this could be approached as a general enum-discriminant collapsing optimisation, with C-like enums + E.g. enum Foo {
A, B, C
}
enum Bar {
X(Foo), Y
}
enum Baz {
S(Bar), T(int)
}would "inline" the discriminant values of their sub-enum. |
Contributor
|
This seems pretty RFC-worthy to me. I've never heard any suggestion that we extend C-like enums in this way. |
Member
|
I agree with @brson that this looks like it needs an RFC to move forward as it's a bit of a language change. Closing. |
lnicola
pushed a commit
to lnicola/rust
that referenced
this pull request
Apr 20, 2024
…r=Veykril internal: make function builder create ast directly I am working on rust-lang#17050. In the process, I noticed a place in the code that could be refactored. Currently, the `function builder` creates the `ast` through the `function template` , but those two processes can be combined into one function. I thought I should work on this first and created a PR.
lnicola
pushed a commit
to lnicola/rust
that referenced
this pull request
Apr 20, 2024
…r=Veykril internal: make function builder create ast directly I am working on rust-lang#17050. In the process, I noticed a place in the code that could be refactored. Currently, the `function builder` creates the `ast` through the `function template` , but those two processes can be combined into one function. I thought I should work on this first and created a PR.
lnicola
pushed a commit
to lnicola/rust
that referenced
this pull request
May 19, 2024
…-new, r=Veykril feature: Make generate function assist generate a function as a constructor if the generated function has the name "new" and is an asscociated function. close rust-lang#17050 This PR makes `generate function assist` generate a function as a constructor if the generated function has the name "new" and is an asscociated function. If the asscociate type is a record struct, it generates the constructor like this. ```rust impl Foo { fn new() -> Self { Self { field_1: todo!(), field_2: todo!() } } } ``` If the asscociate type is a tuple struct, it generates the constructor like this. ```rust impl Foo { fn new() -> Self { Self(todo!(), todo!()) } } ``` If the asscociate type is a unit struct, it generates the constructor like this. ```rust impl Foo { fn new() -> Self { Self } } ``` If the asscociate type is another adt, it generates the constructor like this. ```rust impl Foo { fn new() -> Self { todo!() } } ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows
#[repr(XX)]on more complex enums. Checks for inner variant collisions.Example