Stabilize const_fn_union
This commit is contained in:
parent
36f02f3523
commit
7bf791d162
6 changed files with 5 additions and 33 deletions
|
@ -292,6 +292,8 @@ declare_features! (
|
||||||
(accepted, bindings_after_at, "1.54.0", Some(65490), None),
|
(accepted, bindings_after_at, "1.54.0", Some(65490), None),
|
||||||
/// Allows calling `transmute` in const fn
|
/// Allows calling `transmute` in const fn
|
||||||
(accepted, const_fn_transmute, "1.56.0", Some(53605), None),
|
(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
|
// feature-group-end: accepted features
|
||||||
|
|
|
@ -413,9 +413,6 @@ declare_features! (
|
||||||
/// Allows inferring `'static` outlives requirements (RFC 2093).
|
/// Allows inferring `'static` outlives requirements (RFC 2093).
|
||||||
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
|
(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.
|
/// Allows dereferencing raw pointers during const eval.
|
||||||
(active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
|
(active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
|
||||||
|
|
||||||
|
|
|
@ -748,12 +748,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
|
||||||
| ProjectionElem::Downcast(..)
|
| ProjectionElem::Downcast(..)
|
||||||
| ProjectionElem::Subslice { .. }
|
| ProjectionElem::Subslice { .. }
|
||||||
| ProjectionElem::Field(..)
|
| ProjectionElem::Field(..)
|
||||||
| ProjectionElem::Index(_) => {
|
| 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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`.
|
// Types that cannot appear in the signature or locals of a `const fn`.
|
||||||
pub mod ty {
|
pub mod ty {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
#![feature(const_refs_to_cell)]
|
#![feature(const_refs_to_cell)]
|
||||||
#![feature(const_panic)]
|
#![feature(const_panic)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin)]
|
||||||
#![feature(const_fn_union)]
|
#![cfg_attr(bootstrap, feature(const_fn_union))]
|
||||||
#![feature(const_impl_trait)]
|
#![feature(const_impl_trait)]
|
||||||
#![feature(const_fn_floating_point_arithmetic)]
|
#![feature(const_fn_floating_point_arithmetic)]
|
||||||
#![feature(const_fn_fn_ptr_basics)]
|
#![feature(const_fn_fn_ptr_basics)]
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl<T> [T] {
|
||||||
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
|
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
|
// 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 {
|
pub const fn len(&self) -> usize {
|
||||||
// FIXME: Replace with `crate::ptr::metadata(self)` when that is const-stable.
|
// 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
|
// As of this writing this causes a "Const-stable functions can only call other
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue