diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 96d81f67bc251..9ce5a149697f7 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 deeaa0d709663..8ab61a5d200f7 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 106b7e6777650..109da59aa4380 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 9a03b5e486708..8de11fda7d75b 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 824fd7f79c04b..839be5a143f71 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 de25c984abf90..ce8050cee5b1b 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -100,7 +100,7 @@ impl [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