Skip to content

Commit 7bf791d

Browse files
committed
Stabilize const_fn_union
1 parent 36f02f3 commit 7bf791d

File tree

6 files changed

+5
-33
lines changed

6 files changed

+5
-33
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ declare_features! (
292292
(accepted, bindings_after_at, "1.54.0", Some(65490), None),
293293
/// Allows calling `transmute` in const fn
294294
(accepted, const_fn_transmute, "1.56.0", Some(53605), None),
295+
/// Allows accessing fields of unions inside `const` functions.
296+
(accepted, const_fn_union, "1.56.0", Some(51909), None),
295297

296298
// -------------------------------------------------------------------------
297299
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,6 @@ declare_features! (
413413
/// Allows inferring `'static` outlives requirements (RFC 2093).
414414
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
415415

416-
/// Allows accessing fields of unions inside `const` functions.
417-
(active, const_fn_union, "1.27.0", Some(51909), None),
418-
419416
/// Allows dereferencing raw pointers during const eval.
420417
(active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
421418

compiler/rustc_mir/src/transform/check_consts/check.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
748748
| ProjectionElem::Downcast(..)
749749
| ProjectionElem::Subslice { .. }
750750
| ProjectionElem::Field(..)
751-
| ProjectionElem::Index(_) => {
752-
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
753-
if base_ty.is_union() {
754-
self.check_op(ops::UnionAccess);
755-
}
756-
}
751+
| ProjectionElem::Index(_) => {}
757752
}
758753
}
759754

compiler/rustc_mir/src/transform/check_consts/ops.rs

-22
Original file line numberDiff line numberDiff line change
@@ -501,28 +501,6 @@ impl NonConstOp for ThreadLocalAccess {
501501
}
502502
}
503503

504-
#[derive(Debug)]
505-
pub struct UnionAccess;
506-
impl NonConstOp for UnionAccess {
507-
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
508-
// Union accesses are stable in all contexts except `const fn`.
509-
if ccx.const_kind() != hir::ConstContext::ConstFn {
510-
Status::Allowed
511-
} else {
512-
Status::Unstable(sym::const_fn_union)
513-
}
514-
}
515-
516-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
517-
feature_err(
518-
&ccx.tcx.sess.parse_sess,
519-
sym::const_fn_union,
520-
span,
521-
"unions in const fn are unstable",
522-
)
523-
}
524-
}
525-
526504
// Types that cannot appear in the signature or locals of a `const fn`.
527505
pub mod ty {
528506
use super::*;

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#![feature(const_refs_to_cell)]
8787
#![feature(const_panic)]
8888
#![feature(const_pin)]
89-
#![feature(const_fn_union)]
89+
#![cfg_attr(bootstrap, feature(const_fn_union))]
9090
#![feature(const_impl_trait)]
9191
#![feature(const_fn_floating_point_arithmetic)]
9292
#![feature(const_fn_fn_ptr_basics)]

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<T> [T] {
100100
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
101101
#[inline]
102102
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
103-
#[rustc_allow_const_fn_unstable(const_fn_union)]
103+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_fn_union))]
104104
pub const fn len(&self) -> usize {
105105
// FIXME: Replace with `crate::ptr::metadata(self)` when that is const-stable.
106106
// As of this writing this causes a "Const-stable functions can only call other

0 commit comments

Comments
 (0)