Skip to content

Commit 8a540d0

Browse files
committed
Make some of MaybeUninit's methods const
1 parent e062d1a commit 8a540d0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

core/src/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ extern "rust-intrinsic" {
815815
/// This will statically either panic, or do nothing.
816816
///
817817
/// This intrinsic does not have a stable counterpart.
818+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
818819
pub fn assert_inhabited<T>();
819820

820821
/// A guard for unsafe functions that cannot ever be executed if `T` does not permit

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#![feature(const_type_name)]
101101
#![feature(const_likely)]
102102
#![feature(const_unreachable_unchecked)]
103+
#![feature(const_maybe_assume_init)]
103104
#![feature(custom_inner_attributes)]
104105
#![feature(decl_macro)]
105106
#![feature(doc_cfg)]

core/src/mem/maybe_uninit.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,10 @@ impl<T> MaybeUninit<T> {
314314
/// let data = read(&mut buf);
315315
/// ```
316316
#[unstable(feature = "maybe_uninit_uninit_array", issue = "none")]
317+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
318+
#[rustc_allow_const_fn_unstable(const_maybe_assume_init)]
317319
#[inline(always)]
318-
pub fn uninit_array<const LEN: usize>() -> [Self; LEN] {
320+
pub const fn uninit_array<const LEN: usize>() -> [Self; LEN] {
319321
// SAFETY: An uninitialized `[MaybeUninit<_>; LEN]` is valid.
320322
unsafe { MaybeUninit::<[MaybeUninit<T>; LEN]>::uninit().assume_init() }
321323
}
@@ -503,9 +505,10 @@ impl<T> MaybeUninit<T> {
503505
/// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️
504506
/// ```
505507
#[stable(feature = "maybe_uninit", since = "1.36.0")]
508+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
506509
#[inline(always)]
507510
#[rustc_diagnostic_item = "assume_init"]
508-
pub unsafe fn assume_init(self) -> T {
511+
pub const unsafe fn assume_init(self) -> T {
509512
// SAFETY: the caller must guarantee that `self` is initialized.
510513
// This also means that `self` must be a `value` variant.
511514
unsafe {

0 commit comments

Comments
 (0)