Skip to content

Commit 91772c3

Browse files
committed
Even more const
1 parent 8bd80e2 commit 91772c3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#![feature(const_ptr_offset)]
9393
#![feature(const_ptr_offset_from)]
9494
#![feature(const_raw_ptr_comparison)]
95+
#![feature(const_raw_ptr_deref)]
9596
#![feature(const_slice_from_raw_parts)]
9697
#![feature(const_slice_ptr_len)]
9798
#![feature(const_size_of_val)]

library/core/src/mem/maybe_uninit.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,9 @@ impl<T> MaybeUninit<T> {
813813
///
814814
/// [`assume_init_ref`]: MaybeUninit::assume_init_ref
815815
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
816+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
816817
#[inline(always)]
817-
pub unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T] {
818+
pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T] {
818819
// SAFETY: casting slice to a `*const [T]` is safe since the caller guarantees that
819820
// `slice` is initialized, and`MaybeUninit` is guaranteed to have the same layout as `T`.
820821
// The pointer obtained is valid since it refers to memory owned by `slice` which is a
@@ -834,24 +835,27 @@ impl<T> MaybeUninit<T> {
834835
///
835836
/// [`assume_init_mut`]: MaybeUninit::assume_init_mut
836837
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
838+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
837839
#[inline(always)]
838-
pub unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T] {
840+
pub const unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T] {
839841
// SAFETY: similar to safety notes for `slice_get_ref`, but we have a
840842
// mutable reference which is also guaranteed to be valid for writes.
841843
unsafe { &mut *(slice as *mut [Self] as *mut [T]) }
842844
}
843845

844846
/// Gets a pointer to the first element of the array.
845847
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
848+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
846849
#[inline(always)]
847-
pub fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T {
850+
pub const fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T {
848851
this.as_ptr() as *const T
849852
}
850853

851854
/// Gets a mutable pointer to the first element of the array.
852855
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
856+
#[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")]
853857
#[inline(always)]
854-
pub fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T {
858+
pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T {
855859
this.as_mut_ptr() as *mut T
856860
}
857861
}

0 commit comments

Comments
 (0)