diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2023-05-07 14:12:15 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-07 14:12:15 +0900 |
| commit | aef008aa6d3a86714ed739e7a5bf99f17aa9f6d9 (patch) | |
| tree | 6bc1401dbff98f4a3d472513b7b979de8b67f83b | |
| parent | 58597717e20efb22b68605848f25090e6a5aea4e (diff) | |
| parent | 7e3b93417c620072169a061e7f3c975705723d30 (diff) | |
| download | rust-aef008aa6d3a86714ed739e7a5bf99f17aa9f6d9.tar.gz rust-aef008aa6d3a86714ed739e7a5bf99f17aa9f6d9.zip | |
Rollup merge of #110094 - lukas-code:less-transmute, r=thomcc
clean up `transmute`s in `core` * Use `transmute_unchecked` instead of `transmute_copy` for `MaybeUninit::transpose`. * Use manual transmute for `Option<Ordering>` → `i8`.
| -rw-r--r-- | library/core/src/mem/maybe_uninit.rs | 4 | ||||
| -rw-r--r-- | library/core/src/tuple.rs | 18 |
2 files changed, 9 insertions, 13 deletions
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 2588b7d2bef..d09a24b4b1d 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -1287,7 +1287,7 @@ impl<T, const N: usize> 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)) } + unsafe { intrinsics::transmute_unchecked(self) } } } @@ -1307,6 +1307,6 @@ impl<T, const N: usize> [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)) } + unsafe { intrinsics::transmute_unchecked(self) } } } diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 2a8403c85a4..172e5fccb61 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -1,7 +1,6 @@ // See src/libstd/primitive_docs.rs for documentation. use crate::cmp::Ordering::{self, *}; -use crate::mem::transmute; // Recursive macro for implementing n-ary tuple functions and operations // @@ -142,16 +141,13 @@ macro_rules! maybe_tuple_doc { #[inline] const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool { // FIXME: Just use `==` once that's const-stable on `Option`s. - // This isn't using `match` because that optimizes worse due to - // making a two-step check (`Some` *then* the inner value). - - // SAFETY: There's no public guarantee for `Option<Ordering>`, - // but we're core so we know that it's definitely a byte. - unsafe { - let c: i8 = transmute(c); - let x: i8 = transmute(Some(x)); - c == x - } + // This is mapping `None` to 2 and then doing the comparison afterwards + // because it optimizes better (`None::<Ordering>` is represented as 2). + x as i8 + == match c { + Some(c) => c as i8, + None => 2, + } } // Constructs an expression that performs a lexical ordering using method `$rel`. |
