1
Fork 0

Stabilize some MaybeUninit behavior as const

This commit is contained in:
Jacob Pratt 2021-11-14 00:36:19 -05:00
parent 4919988fe1
commit ad8e6bf5cc
No known key found for this signature in database
GPG key ID: B80E19E4662B5AA4
3 changed files with 8 additions and 8 deletions

View file

@ -853,7 +853,7 @@ extern "rust-intrinsic" {
/// This will statically either panic, or do nothing. /// This will statically either panic, or do nothing.
/// ///
/// This intrinsic does not have a stable counterpart. /// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_assert_type", issue = "none")] #[rustc_const_stable(feature = "const_assert_type", since = "1.59.0")]
pub fn assert_inhabited<T>(); pub fn assert_inhabited<T>();
/// A guard for unsafe functions that cannot ever be executed if `T` does not permit /// A guard for unsafe functions that cannot ever be executed if `T` does not permit

View file

@ -101,7 +101,6 @@
#![feature(const_align_of_val)] #![feature(const_align_of_val)]
#![feature(const_alloc_layout)] #![feature(const_alloc_layout)]
#![feature(const_arguments_as_str)] #![feature(const_arguments_as_str)]
#![feature(const_assert_type)]
#![feature(const_bigint_helper_methods)] #![feature(const_bigint_helper_methods)]
#![feature(const_caller_location)] #![feature(const_caller_location)]
#![feature(const_cell_into_inner)] #![feature(const_cell_into_inner)]
@ -117,7 +116,7 @@
#![feature(const_intrinsic_copy)] #![feature(const_intrinsic_copy)]
#![feature(const_intrinsic_forget)] #![feature(const_intrinsic_forget)]
#![feature(const_likely)] #![feature(const_likely)]
#![feature(const_maybe_uninit_as_ptr)] #![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_maybe_uninit_assume_init)] #![feature(const_maybe_uninit_assume_init)]
#![feature(const_num_from_num)] #![feature(const_num_from_num)]
#![feature(const_ops)] #![feature(const_ops)]

View file

@ -528,7 +528,7 @@ impl<T> MaybeUninit<T> {
/// (Notice that the rules around references to uninitialized data are not finalized yet, but /// (Notice that the rules around references to uninitialized data are not finalized yet, but
/// until they are, it is advisable to avoid them.) /// until they are, it is advisable to avoid them.)
#[stable(feature = "maybe_uninit", since = "1.36.0")] #[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_unstable(feature = "const_maybe_uninit_as_ptr", issue = "75251")] #[rustc_const_stable(feature = "const_maybe_uninit_as_ptr", since = "1.59.0")]
#[inline(always)] #[inline(always)]
pub const fn as_ptr(&self) -> *const T { pub const fn as_ptr(&self) -> *const T {
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
@ -567,7 +567,7 @@ impl<T> MaybeUninit<T> {
/// (Notice that the rules around references to uninitialized data are not finalized yet, but /// (Notice that the rules around references to uninitialized data are not finalized yet, but
/// until they are, it is advisable to avoid them.) /// until they are, it is advisable to avoid them.)
#[stable(feature = "maybe_uninit", since = "1.36.0")] #[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_unstable(feature = "const_maybe_uninit_as_ptr", issue = "75251")] #[rustc_const_unstable(feature = "const_maybe_uninit_as_mut_ptr", issue = "75251")]
#[inline(always)] #[inline(always)]
pub const fn as_mut_ptr(&mut self) -> *mut T { pub const fn as_mut_ptr(&mut self) -> *mut T {
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
@ -620,7 +620,7 @@ impl<T> MaybeUninit<T> {
/// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️ /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️
/// ``` /// ```
#[stable(feature = "maybe_uninit", since = "1.36.0")] #[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init", issue = "none")] #[rustc_const_stable(feature = "const_maybe_uninit_assume_init", since = "1.59.0")]
#[inline(always)] #[inline(always)]
#[rustc_diagnostic_item = "assume_init"] #[rustc_diagnostic_item = "assume_init"]
#[track_caller] #[track_caller]
@ -788,7 +788,8 @@ impl<T> MaybeUninit<T> {
/// } /// }
/// ``` /// ```
#[stable(feature = "maybe_uninit_ref", since = "1.55.0")] #[stable(feature = "maybe_uninit_ref", since = "1.55.0")]
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init", issue = "none")] #[rustc_const_stable(feature = "const_maybe_uninit_assume_init", since = "1.59.0")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_raw_ptr_deref))]
#[inline(always)] #[inline(always)]
pub const unsafe fn assume_init_ref(&self) -> &T { pub const unsafe fn assume_init_ref(&self) -> &T {
// SAFETY: the caller must guarantee that `self` is initialized. // SAFETY: the caller must guarantee that `self` is initialized.
@ -968,7 +969,7 @@ impl<T> MaybeUninit<T> {
/// ///
/// [`assume_init_ref`]: MaybeUninit::assume_init_ref /// [`assume_init_ref`]: MaybeUninit::assume_init_ref
#[unstable(feature = "maybe_uninit_slice", issue = "63569")] #[unstable(feature = "maybe_uninit_slice", issue = "63569")]
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init", issue = "none")] #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")]
#[inline(always)] #[inline(always)]
pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T] { pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T] {
// SAFETY: casting slice to a `*const [T]` is safe since the caller guarantees that // SAFETY: casting slice to a `*const [T]` is safe since the caller guarantees that