Skip to content

Commit 1749359

Browse files
committed
Make assume_init_{ref,mut} const
1 parent 69ab0bc commit 1749359

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#![feature(const_likely)]
104104
#![feature(const_unreachable_unchecked)]
105105
#![feature(const_maybe_uninit_assume_init)]
106+
#![feature(const_maybe_uninit_as_ptr)]
106107
#![feature(custom_inner_attributes)]
107108
#![feature(decl_macro)]
108109
#![feature(doc_cfg)]

library/core/src/mem/maybe_uninit.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,14 @@ impl<T> MaybeUninit<T> {
668668
/// }
669669
/// ```
670670
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
671+
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init", issue = "none")]
671672
#[inline(always)]
672-
pub unsafe fn assume_init_ref(&self) -> &T {
673+
pub const unsafe fn assume_init_ref(&self) -> &T {
673674
// SAFETY: the caller must guarantee that `self` is initialized.
674675
// This also means that `self` must be a `value` variant.
675676
unsafe {
676677
intrinsics::assert_inhabited::<T>();
677-
&*self.value
678+
&*self.as_ptr()
678679
}
679680
}
680681

@@ -790,13 +791,14 @@ impl<T> MaybeUninit<T> {
790791
// to uninitialized data (e.g., in `libcore/fmt/float.rs`). We should make
791792
// a final decision about the rules before stabilization.
792793
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
794+
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init", issue = "none")]
793795
#[inline(always)]
794-
pub unsafe fn assume_init_mut(&mut self) -> &mut T {
796+
pub const unsafe fn assume_init_mut(&mut self) -> &mut T {
795797
// SAFETY: the caller must guarantee that `self` is initialized.
796798
// This also means that `self` must be a `value` variant.
797799
unsafe {
798800
intrinsics::assert_inhabited::<T>();
799-
&mut *self.value
801+
&mut *self.as_mut_ptr()
800802
}
801803
}
802804

0 commit comments

Comments
 (0)