about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-01-11 00:53:54 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-01-20 11:18:05 +0100
commit93efe41b4ef9e0cccedbf962381002d48b3f780c (patch)
tree6acc71b6c09200a251370c096bd9ba4e2bd22818 /src
parent900811e43047fc5593f39b0363373530b02c87e0 (diff)
downloadrust-93efe41b4ef9e0cccedbf962381002d48b3f780c.tar.gz
rust-93efe41b4ef9e0cccedbf962381002d48b3f780c.zip
stabilize transparent_enums
Diffstat (limited to 'src')
-rw-r--r--src/doc/unstable-book/src/language-features/transparent-enums.md93
-rw-r--r--src/librustc_feature/accepted.rs2
-rw-r--r--src/librustc_feature/active.rs3
-rw-r--r--src/librustc_typeck/check/mod.rs10
-rw-r--r--src/test/codegen/repr-transparent-aggregates-1.rs2
-rw-r--r--src/test/codegen/repr-transparent-aggregates-2.rs2
-rw-r--r--src/test/codegen/repr-transparent-aggregates-3.rs2
-rw-r--r--src/test/codegen/repr-transparent.rs2
-rw-r--r--src/test/ui/feature-gates/feature-gate-transparent_enums.rs6
-rw-r--r--src/test/ui/feature-gates/feature-gate-transparent_enums.stderr12
-rw-r--r--src/test/ui/lint/lint-ctypes-enum.rs2
-rw-r--r--src/test/ui/repr/repr-transparent.rs2
12 files changed, 8 insertions, 130 deletions
diff --git a/src/doc/unstable-book/src/language-features/transparent-enums.md b/src/doc/unstable-book/src/language-features/transparent-enums.md
deleted file mode 100644
index 862411ab392..00000000000
--- a/src/doc/unstable-book/src/language-features/transparent-enums.md
+++ /dev/null
@@ -1,93 +0,0 @@
-# `transparent_enums`
-
-The tracking issue for this feature is [#60405]
-
-[60405]: https://github.com/rust-lang/rust/issues/60405
-
-----
-
-The `transparent_enums` feature allows you mark `enum`s as
-`#[repr(transparent)]`. An `enum` may be `#[repr(transparent)]` if it has
-exactly one variant, and that variant matches the same conditions which `struct`
-requires for transparency. Some concrete illustrations follow.
-
-```rust
-#![feature(transparent_enums)]
-
-// This enum has the same representation as `f32`.
-#[repr(transparent)]
-enum SingleFieldEnum {
-    Variant(f32)
-}
-
-// This enum has the same representation as `usize`.
-#[repr(transparent)]
-enum MultiFieldEnum {
-    Variant { field: usize, nothing: () },
-}
-```
-
-For consistency with transparent `struct`s, `enum`s must have exactly one
-non-zero-sized field. If all fields are zero-sized, the `enum` must not be
-`#[repr(transparent)]`:
-
-```rust
-#![feature(transparent_enums)]
-
-// This (non-transparent) enum is already valid in stable Rust:
-pub enum GoodEnum {
-    Nothing,
-}
-
-// Error: transparent enum needs exactly one non-zero-sized field, but has 0
-// #[repr(transparent)]
-// pub enum BadEnum {
-//     Nothing(()),
-// }
-
-// Error: transparent enum needs exactly one non-zero-sized field, but has 0
-// #[repr(transparent)]
-// pub enum BadEmptyEnum {
-//     Nothing,
-// }
-```
-
-The one exception is if the `enum` is generic over `T` and has a field of type
-`T`, it may be `#[repr(transparent)]` even if `T` is a zero-sized type:
-
-```rust
-#![feature(transparent_enums)]
-
-// This enum has the same representation as `T`.
-#[repr(transparent)]
-pub enum GenericEnum<T> {
-    Variant(T, ()),
-}
-
-// This is okay even though `()` is a zero-sized type.
-pub const THIS_IS_OKAY: GenericEnum<()> = GenericEnum::Variant((), ());
-```
-
-Transparent `enum`s require exactly one variant:
-
-```rust
-// Error: transparent enum needs exactly one variant, but has 0
-// #[repr(transparent)]
-// pub enum TooFewVariants {
-// }
-
-// Error: transparent enum needs exactly one variant, but has 2
-// #[repr(transparent)]
-// pub enum TooManyVariants {
-//     First(usize),
-//     Second,
-// }
-```
-
-Like transarent `struct`s, a transparent `enum` of type `E` has the same layout,
-size, and ABI as its single non-ZST field. If it is generic over a type `T`, and
-all its fields are ZSTs except for exactly one field of type `T`, then it has
-the same layout and ABI as `T` (even if `T` is a ZST when monomorphized).
-
-Like transparent `struct`s, transparent `enum`s are FFI-safe if and only if
-their underlying representation type is also FFI-safe.
diff --git a/src/librustc_feature/accepted.rs b/src/librustc_feature/accepted.rs
index 007cee4c764..18dc3e30db1 100644
--- a/src/librustc_feature/accepted.rs
+++ b/src/librustc_feature/accepted.rs
@@ -257,6 +257,8 @@ declare_features! (
     /// Allows relaxing the coherence rules such that
     /// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
     (accepted, re_rebalance_coherence, "1.41.0", Some(55437), None),
+    /// Allows #[repr(transparent)] on univariant enums (RFC 2645).
+    (accepted, transparent_enums, "1.42.0", Some(60405), None),
     /// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
     (accepted, slice_patterns, "1.42.0", Some(62254), None),
 
diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs
index 6af9b6c0872..f20a57ea61c 100644
--- a/src/librustc_feature/active.rs
+++ b/src/librustc_feature/active.rs
@@ -468,9 +468,6 @@ declare_features! (
     /// Allows `if/while p && let q = r && ...` chains.
     (active, let_chains, "1.37.0", Some(53667), None),
 
-    /// Allows #[repr(transparent)] on enums (RFC 2645).
-    (active, transparent_enums, "1.37.0", Some(60405), None),
-
     /// Allows #[repr(transparent)] on unions (RFC 2645).
     (active, transparent_unions, "1.37.0", Some(60405), None),
 
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index f7df630fb90..0c8830717aa 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -2433,16 +2433,6 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) {
     }
     let sp = tcx.sess.source_map().def_span(sp);
 
-    if adt.is_enum() && !tcx.features().transparent_enums {
-        feature_err(
-            &tcx.sess.parse_sess,
-            sym::transparent_enums,
-            sp,
-            "transparent enums are unstable",
-        )
-        .emit();
-    }
-
     if adt.is_union() && !tcx.features().transparent_unions {
         feature_err(
             &tcx.sess.parse_sess,
diff --git a/src/test/codegen/repr-transparent-aggregates-1.rs b/src/test/codegen/repr-transparent-aggregates-1.rs
index 1c8959619d3..018a7ba4756 100644
--- a/src/test/codegen/repr-transparent-aggregates-1.rs
+++ b/src/test/codegen/repr-transparent-aggregates-1.rs
@@ -10,7 +10,7 @@
 // ignore-windows
 // See repr-transparent.rs
 
-#![feature(transparent_enums, transparent_unions)]
+#![feature(transparent_unions)]
 
 #![crate_type="lib"]
 
diff --git a/src/test/codegen/repr-transparent-aggregates-2.rs b/src/test/codegen/repr-transparent-aggregates-2.rs
index afefb9c9f71..56698586720 100644
--- a/src/test/codegen/repr-transparent-aggregates-2.rs
+++ b/src/test/codegen/repr-transparent-aggregates-2.rs
@@ -13,7 +13,7 @@
 // ignore-x86_64
 // See repr-transparent.rs
 
-#![feature(transparent_enums, transparent_unions)]
+#![feature(transparent_unions)]
 
 #![crate_type="lib"]
 
diff --git a/src/test/codegen/repr-transparent-aggregates-3.rs b/src/test/codegen/repr-transparent-aggregates-3.rs
index 1a59c9b48b9..e538be68780 100644
--- a/src/test/codegen/repr-transparent-aggregates-3.rs
+++ b/src/test/codegen/repr-transparent-aggregates-3.rs
@@ -3,7 +3,7 @@
 // only-mips64
 // See repr-transparent.rs
 
-#![feature(transparent_enums, transparent_unions)]
+#![feature(transparent_unions)]
 
 #![crate_type="lib"]
 
diff --git a/src/test/codegen/repr-transparent.rs b/src/test/codegen/repr-transparent.rs
index e705d5ce3cd..49fd015624a 100644
--- a/src/test/codegen/repr-transparent.rs
+++ b/src/test/codegen/repr-transparent.rs
@@ -1,7 +1,7 @@
 // compile-flags: -C no-prepopulate-passes
 
 #![crate_type="lib"]
-#![feature(repr_simd, transparent_enums, transparent_unions)]
+#![feature(repr_simd, transparent_unions)]
 
 use std::marker::PhantomData;
 
diff --git a/src/test/ui/feature-gates/feature-gate-transparent_enums.rs b/src/test/ui/feature-gates/feature-gate-transparent_enums.rs
deleted file mode 100644
index 0a7a73a168e..00000000000
--- a/src/test/ui/feature-gates/feature-gate-transparent_enums.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-#[repr(transparent)]
-enum OkButUnstableEnum { //~ ERROR transparent enums are unstable
-    Foo((), String, ()),
-}
-
-fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr b/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr
deleted file mode 100644
index 8e727c33f20..00000000000
--- a/src/test/ui/feature-gates/feature-gate-transparent_enums.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0658]: transparent enums are unstable
-  --> $DIR/feature-gate-transparent_enums.rs:2:1
-   |
-LL | enum OkButUnstableEnum {
-   | ^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: for more information, see https://github.com/rust-lang/rust/issues/60405
-   = help: add `#![feature(transparent_enums)]` to the crate attributes to enable
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/lint/lint-ctypes-enum.rs b/src/test/ui/lint/lint-ctypes-enum.rs
index 3898e67a07f..ccda005575c 100644
--- a/src/test/ui/lint/lint-ctypes-enum.rs
+++ b/src/test/ui/lint/lint-ctypes-enum.rs
@@ -1,4 +1,4 @@
-#![feature(transparent_enums, transparent_unions)]
+#![feature(transparent_unions)]
 #![feature(ptr_internals)]
 #![deny(improper_ctypes)]
 #![allow(dead_code)]
diff --git a/src/test/ui/repr/repr-transparent.rs b/src/test/ui/repr/repr-transparent.rs
index 730d428ff50..969a323238f 100644
--- a/src/test/ui/repr/repr-transparent.rs
+++ b/src/test/ui/repr/repr-transparent.rs
@@ -3,7 +3,7 @@
 // - repr-transparent-other-reprs.rs
 // - repr-transparent-other-items.rs
 
-#![feature(repr_align, transparent_enums, transparent_unions)]
+#![feature(transparent_unions)]
 
 use std::marker::PhantomData;