Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2008: Future-proofing enums/structs with #[non_exhaustive] attribute #44109
Comments
Mark-Simulacrum
added
B-RFC-approved
T-lang
C-tracking-issue
labels
Aug 26, 2017
This comment has been minimized.
This comment has been minimized.
|
I'd cc @rust-lang/compiler instead. |
scottmcm
referenced this issue
Aug 26, 2017
Merged
Future-proofing enums/structs with #[non_exhaustive] attribute #2008
This comment has been minimized.
This comment has been minimized.
|
im working on a pr for this. how should tests be structured? |
This comment has been minimized.
This comment has been minimized.
|
also: should there be a lint for |
This comment has been minimized.
This comment has been minimized.
|
@tinaun shouldn't they all go under the |
This comment has been minimized.
This comment has been minimized.
|
@tinaun I would expect tests for this to be scattered about in the run-pass and compile-fail and ui directories:
Just to keep things organized, I would make a subdirectory like So I would imagine using ui tests to check for:
The run-pass might be used to test that an exhaustive match within the same crate compiles just fine. |
This comment has been minimized.
This comment has been minimized.
|
@tinaun any progress? need any tips? |
This comment has been minimized.
This comment has been minimized.
|
I'm currently away for the weekend but I would love to have some help with understanding the implementation of privacy in the complier. sorry for forgetting about this! |
This comment has been minimized.
This comment has been minimized.
|
So, this feature shouldn't require too many changes to implement.
|
nikomatsakis
added
E-mentor
WG-compiler-middle
T-compiler
labels
Sep 21, 2017
This comment has been minimized.
This comment has been minimized.
|
@tinaun just checking in -- did those instructions help? Still got questions? =) UPDATE: @tinaun responded on Gitter. |
This comment has been minimized.
This comment has been minimized.
|
Hoping to take a stab at this after speaking with @nikomatsakis in Gitter. @tinaun are you still working on this? Update: @tinaun replied on Gitter. |
danburkert
referenced this issue
Oct 14, 2017
Open
Add #[non_exhaustive] option to enum codegen options #43
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis @eddyb @arielb1 @pnkfelix (I'm not sure who I should be pinging about this, apologies) So far I've implemented most of the mentoring instructions but there are a few things I've run into issues with. In this section where I require I've also not made changes to the visibilities in I hope this is on the right track and I'd appreciate any feedback. |
This comment has been minimized.
This comment has been minimized.
|
To check whether an ADT is within the same crate as the crate you are type-checking, find the def-id of the ADT and check whether it's local - e.g. if you have an |
This comment has been minimized.
This comment has been minimized.
|
For the visibility, you can ask @petrochenkov but I think you want to set the visibility to |
This comment has been minimized.
This comment has been minimized.
|
If you can find me, feel free to ping me on IRC. |
This comment has been minimized.
This comment has been minimized.
|
Thanks, that's super helpful. With regards to the visibility, that's what I was setting the visibility to, but I'll take another stab at it and see what I can come up with. |
This comment has been minimized.
This comment has been minimized.
|
@davidtwco glad to see that @arielb1 got you unblocked! Looking forward to seeing the PR. =) Let us know if you hit any other problems (are here or on gitter) |
This comment has been minimized.
This comment has been minimized.
|
Apologies for how long this is taking and for a further query. Since my previous comment here I think I've got it working with structs and after speaking with @nikomatsakis in Gitter earlier today, I've added a bunch more tests for cases that I hadn't considered. There are only five tests that still don't pass: The first of which is related to instantiating a tuple struct, I think I've went wrong with the visibility somewhere for this so I'm going to look into that. The second of which is similar but for instantiating a unit struct. The rest of which are all related to a lack of errors for things that should fail on enums with the attribute. @nikomatsakis mentioned that there are two cases with enums, handling new variants and new fields to existing variants - I do believe that the new fields case is handled by the existing structs code but I'm not 100% sure. However, I don't think the new variants case is handled. All the help so far as been fantastic so I appreciate that. |
panicbit
referenced this issue
Oct 18, 2017
Merged
Switch to serde for serialization/deserialization #3
davidtwco
referenced this issue
Oct 19, 2017
Merged
RFC 2008: Future-proofing enums/structs with #[non_exhaustive] attribute #45394
bors
added a commit
that referenced
this issue
Jul 19, 2018
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/compiler @rust-lang/lang As far as I'm aware, with #51854 having landed, the only thing remaining for this RFC is implementation of the attribute for variants (they currently share a |
This comment has been minimized.
This comment has been minimized.
|
@davidtwco I see a few things listed in the issue header:
Have the other two been resolved? |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis #49345 resolved the latter two issues. The first issue is still pending. |
This comment has been minimized.
This comment has been minimized.
|
So, to implement rust/src/librustc_typeck/check/mod.rs Lines 3575 to 3582 in fefe816 In that code, we have this variable Currently, we have the
When we build the adt-def for a struct, if it is tagged with Once this is done, the existing code is almost correct, but it must be changed from saying The rust/src/librustc_typeck/collect.rs Lines 558 to 560 in fefe816 You can see that structs have one variant, built here: rust/src/librustc_typeck/collect.rs Lines 594 to 597 in fefe816 The existing flag is set in Lines 1912 to 1914 in fefe816 Anyway, I'm not -- I confess -- 100% sure where to set the flag best, but that's the idea. =) |
This comment has been minimized.
This comment has been minimized.
|
Submitted #52775 with an implementation of the attribute on variants. |
This comment has been minimized.
This comment has been minimized.
|
In the currently implementation, E0639 fires when the attribute is applied to enums, while it should only be relevant when the attribute is on a specific variant: #53549 |
nikomatsakis
referenced this issue
Aug 30, 2018
Merged
fix `is_non_exhaustive` confusion between structs and enums #53721
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/lang Can we stabilize what’s implemented (attribute on enum types to allow adding variants later) without waiting on what’s not (yet)? (attribute on struct types or enum variants to allow adding fields later) |
This comment has been minimized.
This comment has been minimized.
|
Seems reasonable to me -- @petrochenkov are you aware of any "gotchas" there? |
This comment has been minimized.
This comment has been minimized.
|
No, not aware. |
This comment has been minimized.
This comment has been minimized.
|
Was the non-exhaustiveness added to rustdoc or is that still a to-do? I'm fine with just stabilising enums and leaving the rest unstable. |
This comment has been minimized.
This comment has been minimized.
|
@clarcharr It has been added to rustdoc. |
Centril
removed
the
T-compiler
label
Jan 22, 2019
Thomasdezeeuw
referenced this issue
Feb 1, 2019
Closed
Add non exhaustive attribute to PollOption #46
This comment has been minimized.
This comment has been minimized.
|
I'm very much in favor of stabilizing this for enums and leaving the rest unstable. |
This comment has been minimized.
This comment has been minimized.
|
As far as I'm aware, the only thing that needs to be done is actually separating out the feature flag and an FCP. The FCP could probably be started before that's merged though, as it can be done as part of stabilisation. |
jonhoo
referenced this issue
Mar 8, 2019
Closed
Make the dependencies which are not directly used for flamegraph generation optional #72
This was referenced Mar 23, 2019
bors
added a commit
that referenced
this issue
Mar 24, 2019
museun
referenced this issue
Mar 27, 2019
Open
Make some (all?) of the enums have a non-exhaustive variant #27
Centril
added a commit
to Centril/rust
that referenced
this issue
Mar 29, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Mar 30, 2019
This comment has been minimized.
This comment has been minimized.
|
With #59376 having landed, |
scottmcm commentedAug 26, 2017
•
edited by davidtwco
This is a tracking issue for the RFC "Future-proofing enums/structs with #[non_exhaustive] attribute" (rust-lang/rfcs#2008).
Steps:
Issues to be resolved prior to stabilization
#[non_exhaustive]is not yet implemented for enum variants.#[non_exhaustive(foo)]) and in arbitrary locations, including suspicious ones like traits(#[non_exhaustive] trait Trait {}).