forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#89884 - Mark-Simulacrum:revert-enum-discr, r=…
…wesleywiser Revert enum discriminants Reverts stabilization of arbitrary enum discriminants per rust-lang#88621 (comment). Reopens rust-lang#60553.
- Loading branch information
Showing
22 changed files
with
221 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# `arbitrary_enum_discriminant` | ||
|
||
The tracking issue for this feature is: [#60553] | ||
|
||
[#60553]: https://github.com/rust-lang/rust/issues/60553 | ||
|
||
------------------------ | ||
|
||
The `arbitrary_enum_discriminant` feature permits tuple-like and | ||
struct-like enum variants with `#[repr(<int-type>)]` to have explicit discriminants. | ||
|
||
## Examples | ||
|
||
```rust | ||
#![feature(arbitrary_enum_discriminant)] | ||
|
||
#[allow(dead_code)] | ||
#[repr(u8)] | ||
enum Enum { | ||
Unit = 3, | ||
Tuple(u16) = 2, | ||
Struct { | ||
a: u8, | ||
b: u16, | ||
} = 1, | ||
} | ||
|
||
impl Enum { | ||
fn tag(&self) -> u8 { | ||
unsafe { *(self as *const Self as *const u8) } | ||
} | ||
} | ||
|
||
assert_eq!(3, Enum::Unit.tag()); | ||
assert_eq!(2, Enum::Tuple(5).tag()); | ||
assert_eq!(1, Enum::Struct{a: 7, b: 11}.tag()); | ||
``` |
1 change: 1 addition & 0 deletions
1
src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr
This file contains 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
This file contains 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
This file contains 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
10 changes: 10 additions & 0 deletions
10
src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![crate_type="lib"] | ||
|
||
enum Enum { | ||
Unit = 1, | ||
//~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants | ||
Tuple() = 2, | ||
//~^ ERROR discriminants on non-unit variants are experimental | ||
Struct{} = 3, | ||
//~^ ERROR discriminants on non-unit variants are experimental | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error[E0658]: discriminants on non-unit variants are experimental | ||
--> $DIR/feature-gate-arbitrary_enum_discriminant.rs:6:13 | ||
| | ||
LL | Tuple() = 2, | ||
| ^ | ||
| | ||
= note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information | ||
= help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable | ||
|
||
error[E0658]: discriminants on non-unit variants are experimental | ||
--> $DIR/feature-gate-arbitrary_enum_discriminant.rs:8:14 | ||
| | ||
LL | Struct{} = 3, | ||
| ^ | ||
| | ||
= note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information | ||
= help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable | ||
|
||
error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants | ||
--> $DIR/feature-gate-arbitrary_enum_discriminant.rs:4:10 | ||
| | ||
LL | Unit = 1, | ||
| ^ disallowed custom discriminant | ||
LL | | ||
LL | Tuple() = 2, | ||
| ----------- tuple variant defined here | ||
LL | | ||
LL | Struct{} = 3, | ||
| ------------ struct variant defined here | ||
| | ||
= note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information | ||
= help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
2 changes: 1 addition & 1 deletion
2
src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum X { | ||
A = 3, | ||
//~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants | ||
B(usize) | ||
} | ||
|
||
fn main() {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants | ||
--> $DIR/issue-17383.rs:2:9 | ||
| | ||
LL | A = 3, | ||
| ^ disallowed custom discriminant | ||
LL | | ||
LL | B(usize) | ||
| -------- tuple variant defined here | ||
| | ||
= note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information | ||
= help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
enum Color { | ||
Red = 0xff0000, | ||
//~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants | ||
Green = 0x00ff00, | ||
Blue = 0x0000ff, | ||
Black = 0x000000, | ||
White = 0xffffff, | ||
Other(usize), | ||
Other2(usize, usize), | ||
} | ||
|
||
fn main() {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants | ||
--> $DIR/tag-variant-disr-non-nullary.rs:2:11 | ||
| | ||
LL | Red = 0xff0000, | ||
| ^^^^^^^^ disallowed custom discriminant | ||
LL | | ||
LL | Green = 0x00ff00, | ||
| ^^^^^^^^ disallowed custom discriminant | ||
LL | Blue = 0x0000ff, | ||
| ^^^^^^^^ disallowed custom discriminant | ||
LL | Black = 0x000000, | ||
| ^^^^^^^^ disallowed custom discriminant | ||
LL | White = 0xffffff, | ||
| ^^^^^^^^ disallowed custom discriminant | ||
LL | Other(usize), | ||
| ------------ tuple variant defined here | ||
LL | Other2(usize, usize), | ||
| -------------------- tuple variant defined here | ||
| | ||
= note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information | ||
= help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |