Stabilize const_fn_union

This commit is contained in:
Jacob Pratt 2021-06-03 02:16:56 -04:00
parent 36f02f3523
commit 7bf791d162
No known key found for this signature in database
GPG Key ID: B80E19E4662B5AA4
6 changed files with 5 additions and 33 deletions

View File

@ -292,6 +292,8 @@ macro_rules! 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

View File

@ -413,9 +413,6 @@ pub fn set(&self, features: &mut Features, span: Span) {
/// 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),

View File

@ -748,12 +748,7 @@ fn visit_projection_elem(
| 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(_) => {}
}
}

View File

@ -501,28 +501,6 @@ fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<
}
}
#[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::*;

View File

@ -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)]

View File

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