diff options
| author | Albin Hedman <albin9604@gmail.com> | 2020-12-02 03:01:18 +0100 |
|---|---|---|
| committer | Albin Hedman <albin9604@gmail.com> | 2020-12-02 03:22:47 +0100 |
| commit | 91772c35c83f369283838ab049712a5f746e11ef (patch) | |
| tree | 240aedae10356bed4d6d8c00630dd8eadf43f354 | |
| parent | 8bd80e25f0bdb7a3282fecee148afed966067f1e (diff) | |
| download | rust-91772c35c83f369283838ab049712a5f746e11ef.tar.gz rust-91772c35c83f369283838ab049712a5f746e11ef.zip | |
Even more const
| -rw-r--r-- | library/core/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/core/src/mem/maybe_uninit.rs | 12 |
2 files changed, 9 insertions, 4 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 5d56a22bfa5..a901375a958 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -92,6 +92,7 @@ #![feature(const_ptr_offset)] #![feature(const_ptr_offset_from)] #![feature(const_raw_ptr_comparison)] +#![feature(const_raw_ptr_deref)] #![feature(const_slice_from_raw_parts)] #![feature(const_slice_ptr_len)] #![feature(const_size_of_val)] diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index cb32c909717..6251355b909 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -813,8 +813,9 @@ impl<T> MaybeUninit<T> { /// /// [`assume_init_ref`]: MaybeUninit::assume_init_ref #[unstable(feature = "maybe_uninit_slice", issue = "63569")] + #[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")] #[inline(always)] - pub 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 // `slice` is initialized, and`MaybeUninit` is guaranteed to have the same layout as `T`. // The pointer obtained is valid since it refers to memory owned by `slice` which is a @@ -834,8 +835,9 @@ impl<T> MaybeUninit<T> { /// /// [`assume_init_mut`]: MaybeUninit::assume_init_mut #[unstable(feature = "maybe_uninit_slice", issue = "63569")] + #[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")] #[inline(always)] - pub unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T] { + pub const unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T] { // SAFETY: similar to safety notes for `slice_get_ref`, but we have a // mutable reference which is also guaranteed to be valid for writes. unsafe { &mut *(slice as *mut [Self] as *mut [T]) } @@ -843,15 +845,17 @@ impl<T> MaybeUninit<T> { /// Gets a pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] + #[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")] #[inline(always)] - pub fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T { + pub const fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T { this.as_ptr() as *const T } /// Gets a mutable pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] + #[rustc_const_unstable(feature = "const_maybe_assume_init", issue = "none")] #[inline(always)] - pub fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T { + pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T { this.as_mut_ptr() as *mut T } } |
