diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 1e461abe537b1..4f128f348e57c 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -952,8 +952,9 @@ impl Rc { #[inline] #[unstable(feature = "rc_as_weak", issue = "100472")] #[must_use] - pub const fn as_weak<'a>(this: &'a Self) -> &'a Weak { - unsafe { mem::transmute::<&'a Rc, &'a Weak>(this) } + pub const fn as_weak(this: &Self) -> &Weak { + let weak = this as *const Self as *const Weak; + unsafe { &*weak } } /// Gets the number of [`Weak`] pointers to this allocation. diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index d5408335fa255..a0f89344fee47 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -979,8 +979,9 @@ impl Arc { #[inline] #[unstable(feature = "rc_as_weak", issue = "100472")] #[must_use] - pub const fn as_weak<'a>(this: &'a Self) -> &'a Weak { - unsafe { mem::transmute::<&'a Arc, &'a Weak>(this) } + pub const fn as_weak(this: &Self) -> &Weak { + let weak = this as *const Self as *const Weak; + unsafe { &*weak } } /// Gets the number of [`Weak`] pointers to this allocation.