-
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
RFC 2008: Enum Variants #59376
RFC 2008: Enum Variants #59376
Conversation
I anticipate a lot of review comments so I'd appreciate any feedback and I'm happy to make any requested changes. I tried to split some of the later commits up to make it easier to review but unfortunately wasn't able to with the earlier commits that did the bulk of the refactoring. |
Looks like something went wrong during rebase because |
This work would benefit from splitting into two PRs - one for the |
I may be mistaken, but isn’t this due to #58140 landing?
I’ll split this into two PRs. I wanted to make the RFC 2008 changes on top so that I could confirm that the refactoring did work as expected. |
Exactly. |
|
516fadf
to
fa89ba1
Compare
This comment has been minimized.
This comment has been minimized.
516f410
to
1b382f3
Compare
Separate `DefId`s for variants and their constructors Part of #44109. Split off from #59376. See [Zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/rfc-2008/near/132663140) for previous discussion. r? @petrochenkov
1b382f3
to
147a385
Compare
Rebased atop master now #59382 has landed, unblocked. |
08c4943
to
07de867
Compare
cc @rust-lang/rustdoc for the final commit which modifies rustdoc to extend existing non-exhaustive support to enum variants. |
r=me for non-rustdoc changes |
This commit removes the check that disallows the `#[non_exhaustive]` attribute from being placed on enum variants and removes the associated tests. Further, this commit lowers the visibility of enum variant constructors when the variant is marked as non-exhaustive.
07de867
to
4de38fa
Compare
Does it generate a whole page for enum variants now? |
This commit updates the unstable book and diagnostics to reflect that the `#[non_exhaustive]` attribute is now available for enum variants.
This commit adds support for non-exhaustive enum variants in rustdoc, extending the existing support for non-exhaustive enums and structs.
4de38fa
to
49a6da2
Compare
@GuillaumeGomez When an enum variant is marked as enum Foo {
#[non_exhaustive]
Unit,
#[non_exhaustive]
Tuple(u8, u8),
#[non_exhaustive]
Struct { x: u8, y: u8 },
} Then it is displayed like this: This expands to: For reference, here are the equivalent messages for structs (expanded) and enums (expanded). All that the final commit of this PR does is add support for these messages and make it so that the non-exhaustive sections always start collapsed (since they're a lot of repetitive text otherwise). |
Ah I see! Looks good to me then. |
Rustdoc code looks good. Thanks for the screenshots! @bors r=petrochenkov,QuietMisdreavus |
📌 Commit 49a6da2 has been approved by |
…, r=petrochenkov,QuietMisdreavus RFC 2008: Enum Variants Part of rust-lang#44109. See [Zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/rfc-2008/near/132663140) for previous discussion. r? @petrochenkov cc @nikomatsakis
…, r=petrochenkov,QuietMisdreavus RFC 2008: Enum Variants Part of rust-lang#44109. See [Zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/rfc-2008/near/132663140) for previous discussion. r? @petrochenkov cc @nikomatsakis
Rollup of 10 pull requests Successful merges: - #59376 (RFC 2008: Enum Variants) - #59453 (Recover from parse error in tuple syntax) - #59455 (Account for short-hand field syntax when suggesting borrow) - #59499 (Fix broken download link in the armhf-gnu image) - #59512 (implement `AsRawFd` for stdio locks) - #59525 (Whitelist some rustc attrs) - #59528 (Improve the dbg! macro docs ) - #59532 (In doc examples, don't ignore read/write results) - #59534 (rustdoc: collapse blanket impls in the same way as normal impls) - #59537 (Fix OnceWith docstring.) Failed merges: r? @ghost
Fix cross-crate visibility of fictive variant constructors After merging rust-lang#59376 I realized that the code in the decoder wasn't entirely correct - we "decoded" fictive variant constructors with their variant's visibility, which could be public, rather than demoted to `pub(crate)`. Fictive constructors are not directly usable in expression/patterns, but the effect still can be observed with imports. r? @davidtwco
Fix cross-crate visibility of fictive variant constructors After merging rust-lang#59376 I realized that the code in the decoder wasn't entirely correct - we "decoded" fictive variant constructors with their variant's visibility, which could be public, rather than demoted to `pub(crate)`. Fictive constructors are not directly usable in expression/patterns, but the effect still can be observed with imports. r? @davidtwco
Part of #44109. See Zulip topic for previous discussion.
r? @petrochenkov
cc @nikomatsakis