Skip to content
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: Variants #52775

Closed
wants to merge 2 commits into from
Closed

Conversation

davidtwco
Copy link
Member

Part of #44109.

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2018
@petrochenkov petrochenkov self-assigned this Jul 27, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me but let's let @petrochenkov review

ty::VariantDef {
did,
name,
discr,
fields,
ctor_kind: CtorKind::from_hir(def),
can_extend_field_list: tcx.has_attr(did, "non_exhaustive"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One weird thing -- I'm not sure how this will work -- the did in the case of a tuple-struct is I think the synthetic def-id creator for the struct constructor? We just need to be sure to test #[non_exhaustive] pub struct Foo(pub u32)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I guess we have some tests for that already so... seems ok.

@nikomatsakis nikomatsakis removed their assignment Jul 28, 2018
@petrochenkov
Copy link
Contributor

petrochenkov commented Jul 29, 2018

Hm, this is not actually an implementation of RFC 2008, it's something else.

This PR requires tuple struct patterns to mention .. when matching tuple variants (V(a, b) - ERROR, V(a, .., b) - OK), but misses checks for V(a, b) in expressions and for unit variants in both expressions and patterns.

This doesn't provide required future-proofing since V(a, .., b) can still break if new fields of incompatible types are added into variant.
That's why RFC 2008 specifies other behavior - #[non_exhaustive] lowers visibility of constructors to pub(crate). For structs this behavior was already implemented in #45394, but this PR breaks it.

The original PR didn't implement #[non_exhaustive] for variants because variants and their constructors share DefIds, so they cannot be assigned different visibilities, so constructor's visibility cannot be lowered to pub(crate).
The preliminary work on separation of DefIds is still not done, so the implementation for variants is still blocked.

(Note that #[non_exhaustive] not being implemented for variants doesn't stop its stabilization in other places in any way.)

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2018
@davidtwco
Copy link
Member Author

Thanks @petrochenkov. I'll close this PR for now and a new one can be opened with a proper implementation of RFC 2008 for variants once the preliminary work to support different visibilities of variants and constructors has been completed (I'm happy to work on this and anything blocking it if provided some pointers on what needs changed).

@davidtwco davidtwco closed this Jul 29, 2018
@davidtwco davidtwco deleted the rfc-2008-variants branch March 30, 2019 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants