diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index a42f1c3b4bbae..4ead5894cbfed 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1884,6 +1884,17 @@ impl From for Rc { } } +#[stable(feature = "shared_from_str", since = "1.63.0")] +impl From> for Rc<[u8]> { + #[inline] + fn from(s: Rc) -> Self { + // SAFETY: the cast from `*const str` to `*const [u8]` is safe since + // `str` has the same layout as `[u8]` (only libstd can make this + // guarantee). + unsafe { Rc::from_raw(Rc::into_raw(s) as *const [u8]) } + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] impl From> for Rc { diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index a19999cd72580..7eb9d5d60fa64 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -2484,6 +2484,17 @@ impl From for Arc { } } +#[stable(feature = "shared_from_str", since = "1.63.0")] +impl From> for Arc<[u8]> { + #[inline] + fn from(s: Arc) -> Self { + // SAFETY: the cast from `*const str` to `*const [u8]` is safe since + // `str` has the same layout as `[u8]` (only libstd can make this + // guarantee). + unsafe { Arc::from_raw(Arc::into_raw(s) as *const [u8]) } + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] impl From> for Arc {