about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-10-19 14:05:52 +0530
committerGitHub <noreply@github.com>2022-10-19 14:05:52 +0530
commitf4afb9d9ec4a8b787acd477c9f3984d0db82087b (patch)
tree9dd3e5ff3ee8d50ea7a5dc7d4813da332ad7e264
parent48c5e0c262c4b454ec1c4528b5a9d81d3fc6bde6 (diff)
parent1a1ebb080f181cef75533dc829ec571745b1f174 (diff)
Rollup merge of #103127 - SUPERCILEX:inline-const-uninit, r=scottmcm
Make transpose const and inline

r? `@scottmcm`

- These should have been const from the beginning since we're never going to do more than a transmute.
- Inline these always because that's what every other method in MaybeUninit which simply casts does. :) Ok, but a stronger justification is that because we're taking in arrays by `self`, not inlining would defeat the whole purpose of using `MaybeUninit` due to the copying.
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/mem/maybe_uninit.rs6
2 files changed, 5 insertions, 2 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index da84763836e..2fd8180f8b2 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -217,6 +217,7 @@
 #![feature(unboxed_closures)]
 #![feature(unsized_fn_params)]
 #![feature(asm_const)]
+#![feature(const_transmute_copy)]
 //
 // Target features:
 #![feature(arm_target_feature)]
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs
index 2ae96367628..efad9a9391b 100644
--- a/library/core/src/mem/maybe_uninit.rs
+++ b/library/core/src/mem/maybe_uninit.rs
@@ -1297,7 +1297,8 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
     /// let data: [MaybeUninit<u8>; 1000] = MaybeUninit::uninit().transpose();
     /// ```
     #[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
-    pub fn transpose(self) -> [MaybeUninit<T>; N] {
+    #[inline]
+    pub const fn transpose(self) -> [MaybeUninit<T>; N] {
         // SAFETY: T and MaybeUninit<T> have the same layout
         unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
     }
@@ -1316,7 +1317,8 @@ impl<T, const N: usize> [MaybeUninit<T>; N] {
     /// let data: MaybeUninit<[u8; 1000]> = data.transpose();
     /// ```
     #[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
-    pub fn transpose(self) -> MaybeUninit<[T; N]> {
+    #[inline]
+    pub const fn transpose(self) -> MaybeUninit<[T; N]> {
         // SAFETY: T and MaybeUninit<T> have the same layout
         unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
     }