Revert "Stabilize arbitrary_enum_discriminant"

This reverts commit 7a62f29f31.
This commit is contained in:
Mark Rousskov 2021-10-14 10:57:56 -04:00
parent c34ac8747c
commit 8485e6fdec
21 changed files with 221 additions and 13 deletions

View file

@ -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());
```

View file

@ -1,4 +1,5 @@
#![crate_type="lib"]
#![feature(arbitrary_enum_discriminant)]
enum Enum {
//~^ ERROR `#[repr(inttype)]` must be specified

View file

@ -1,5 +1,5 @@
error[E0732]: `#[repr(inttype)]` must be specified
--> $DIR/arbitrary_enum_discriminant-no-repr.rs:3:1
--> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1
|
LL | / enum Enum {
LL | |

View file

@ -1,5 +1,5 @@
// run-pass
#![feature(const_raw_ptr_deref, test)]
#![feature(arbitrary_enum_discriminant, const_raw_ptr_deref, test)]
extern crate test;

View file

@ -1,6 +1,6 @@
// run-pass
#![allow(stable_features)]
#![feature(core, core_intrinsics)]
#![feature(arbitrary_enum_discriminant, core, core_intrinsics)]
extern crate core;
use core::intrinsics::discriminant_value;

View file

@ -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
}

View file

@ -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`.

View file

@ -1,4 +1,4 @@
#![feature(core_intrinsics)]
#![feature(arbitrary_enum_discriminant, core_intrinsics)]
extern crate core;
use core::intrinsics::discriminant_value;

View file

@ -1,4 +1,4 @@
#![feature(core_intrinsics)]
#![feature(arbitrary_enum_discriminant, core_intrinsics)]
extern crate core;
use core::intrinsics::discriminant_value;

View file

@ -1,5 +1,5 @@
// run-pass
#![feature(repr128)]
#![feature(repr128, arbitrary_enum_discriminant)]
//~^ WARN the feature `repr128` is incomplete
#[derive(PartialEq, Debug)]

View file

@ -1,7 +1,7 @@
warning: the feature `repr128` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-70509-partial_eq.rs:2:12
|
LL | #![feature(repr128)]
LL | #![feature(repr128, arbitrary_enum_discriminant)]
| ^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

View file

@ -6,7 +6,7 @@
// This test checks panic emitted from `mem::{uninitialized,zeroed}`.
#![feature(never_type)]
#![feature(never_type, arbitrary_enum_discriminant)]
#![allow(deprecated, invalid_value)]
use std::{

View file

@ -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() {}

View file

@ -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`.

View file

@ -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() {}

View file

@ -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`.