diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
commit | 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch) | |
tree | d325add32978dbdc1db975a438b3a77d571b1ab8 /vendor/zerovec/src/ule/plain.rs | |
parent | Releasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/zerovec/src/ule/plain.rs')
-rw-r--r-- | vendor/zerovec/src/ule/plain.rs | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/vendor/zerovec/src/ule/plain.rs b/vendor/zerovec/src/ule/plain.rs index 0b1bbb441..49455d45f 100644 --- a/vendor/zerovec/src/ule/plain.rs +++ b/vendor/zerovec/src/ule/plain.rs @@ -7,10 +7,7 @@ use super::*; use crate::ZeroSlice; -use core::{ - mem, - num::{NonZeroI8, NonZeroU8}, -}; +use core::num::{NonZeroI8, NonZeroU8}; /// A u8 array of little-endian data with infallible conversions to and from &[u8]. #[repr(transparent)] @@ -100,19 +97,7 @@ macro_rules! impl_const_constructors { let len = bytes.len(); #[allow(clippy::modulo_one)] if len % $size == 0 { - unsafe { - // Most of the slice manipulation functions are not yet const-stable, - // so we construct a slice with the right metadata and cast its type - // https://rust-lang.github.io/unsafe-code-guidelines/layout/pointers.html#notes - // - // Safety: - // * [u8] and [RawBytesULE<N>] have different lengths but the same alignment - // * ZeroSlice<$base> is repr(transparent) with [RawBytesULE<N>] - let [ptr, _]: [usize; 2] = mem::transmute(bytes); - let new_len = len / $size; - let raw = [ptr, new_len]; - Ok(mem::transmute(raw)) - } + Ok(unsafe { Self::from_bytes_unchecked(bytes) }) } else { Err(ZeroVecError::InvalidLength { ty: concat!("<const construct: ", $size, ">"), |