about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2021-06-03 02:16:56 -0400
committerJacob Pratt <jacob@jhpratt.dev>2021-07-27 16:03:33 -0400
commit7bf791d162705447b97819c16d286dec2a3f34f1 (patch)
tree1abc5e1bd9283ff169896d964ff72213b921964e
parent36f02f352392f216d778808818d0e4ed56714f3c (diff)
downloadrust-7bf791d162705447b97819c16d286dec2a3f34f1.tar.gz
rust-7bf791d162705447b97819c16d286dec2a3f34f1.zip
Stabilize `const_fn_union`
-rw-r--r--compiler/rustc_feature/src/accepted.rs2
-rw-r--r--compiler/rustc_feature/src/active.rs3
-rw-r--r--compiler/rustc_mir/src/transform/check_consts/check.rs7
-rw-r--r--compiler/rustc_mir/src/transform/check_consts/ops.rs22
-rw-r--r--library/core/src/lib.rs2
-rw-r--r--library/core/src/slice/mod.rs2
6 files changed, 5 insertions, 33 deletions
diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs
index 96d81f67bc2..9ce5a149697 100644
--- a/compiler/rustc_feature/src/accepted.rs
+++ b/compiler/rustc_feature/src/accepted.rs
@@ -292,6 +292,8 @@ declare_features! (
     (accepted, bindings_after_at, "1.54.0", Some(65490), None),
     /// Allows calling `transmute` in const fn
     (accepted, const_fn_transmute, "1.56.0", Some(53605), None),
+    /// Allows accessing fields of unions inside `const` functions.
+    (accepted, const_fn_union, "1.56.0", Some(51909), None),
 
     // -------------------------------------------------------------------------
     // feature-group-end: accepted features
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index deeaa0d7096..8ab61a5d200 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -413,9 +413,6 @@ declare_features! (
     /// Allows inferring `'static` outlives requirements (RFC 2093).
     (active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
 
-    /// Allows accessing fields of unions inside `const` functions.
-    (active, const_fn_union, "1.27.0", Some(51909), None),
-
     /// Allows dereferencing raw pointers during const eval.
     (active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
 
diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_mir/src/transform/check_consts/check.rs
index 106b7e67776..109da59aa43 100644
--- a/compiler/rustc_mir/src/transform/check_consts/check.rs
+++ b/compiler/rustc_mir/src/transform/check_consts/check.rs
@@ -748,12 +748,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
             | ProjectionElem::Downcast(..)
             | ProjectionElem::Subslice { .. }
             | ProjectionElem::Field(..)
-            | ProjectionElem::Index(_) => {
-                let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
-                if base_ty.is_union() {
-                    self.check_op(ops::UnionAccess);
-                }
-            }
+            | ProjectionElem::Index(_) => {}
         }
     }
 
diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs
index 9a03b5e4867..8de11fda7d7 100644
--- a/compiler/rustc_mir/src/transform/check_consts/ops.rs
+++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs
@@ -501,28 +501,6 @@ impl NonConstOp for ThreadLocalAccess {
     }
 }
 
-#[derive(Debug)]
-pub struct UnionAccess;
-impl NonConstOp for UnionAccess {
-    fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
-        // Union accesses are stable in all contexts except `const fn`.
-        if ccx.const_kind() != hir::ConstContext::ConstFn {
-            Status::Allowed
-        } else {
-            Status::Unstable(sym::const_fn_union)
-        }
-    }
-
-    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
-        feature_err(
-            &ccx.tcx.sess.parse_sess,
-            sym::const_fn_union,
-            span,
-            "unions in const fn are unstable",
-        )
-    }
-}
-
 // Types that cannot appear in the signature or locals of a `const fn`.
 pub mod ty {
     use super::*;
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 824fd7f79c0..839be5a143f 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -86,7 +86,7 @@
 #![feature(const_refs_to_cell)]
 #![feature(const_panic)]
 #![feature(const_pin)]
-#![feature(const_fn_union)]
+#![cfg_attr(bootstrap, feature(const_fn_union))]
 #![feature(const_impl_trait)]
 #![feature(const_fn_floating_point_arithmetic)]
 #![feature(const_fn_fn_ptr_basics)]
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index de25c984abf..ce8050cee5b 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -100,7 +100,7 @@ impl<T> [T] {
     #[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
     #[inline]
     // SAFETY: const sound because we transmute out the length field as a usize (which it must be)
-    #[rustc_allow_const_fn_unstable(const_fn_union)]
+    #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_fn_union))]
     pub const fn len(&self) -> usize {
         // FIXME: Replace with `crate::ptr::metadata(self)` when that is const-stable.
         // As of this writing this causes a "Const-stable functions can only call other