Skip to content

Commit f4afb9d

Browse files
authored
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.
2 parents 48c5e0c + 1a1ebb0 commit f4afb9d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
#![feature(unboxed_closures)]
218218
#![feature(unsized_fn_params)]
219219
#![feature(asm_const)]
220+
#![feature(const_transmute_copy)]
220221
//
221222
// Target features:
222223
#![feature(arm_target_feature)]

Diff for: library/core/src/mem/maybe_uninit.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,8 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
12971297
/// let data: [MaybeUninit<u8>; 1000] = MaybeUninit::uninit().transpose();
12981298
/// ```
12991299
#[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
1300-
pub fn transpose(self) -> [MaybeUninit<T>; N] {
1300+
#[inline]
1301+
pub const fn transpose(self) -> [MaybeUninit<T>; N] {
13011302
// SAFETY: T and MaybeUninit<T> have the same layout
13021303
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
13031304
}
@@ -1316,7 +1317,8 @@ impl<T, const N: usize> [MaybeUninit<T>; N] {
13161317
/// let data: MaybeUninit<[u8; 1000]> = data.transpose();
13171318
/// ```
13181319
#[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
1319-
pub fn transpose(self) -> MaybeUninit<[T; N]> {
1320+
#[inline]
1321+
pub const fn transpose(self) -> MaybeUninit<[T; N]> {
13201322
// SAFETY: T and MaybeUninit<T> have the same layout
13211323
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
13221324
}

0 commit comments

Comments
 (0)