diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index b883a0c2ec7f..4d3daf965e75 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -287,6 +287,18 @@ where } } +impl From<&NonZero> for &T +where + T: ZeroablePrimitive, +{ + #[inline] + fn from(nonzero: &NonZero) -> Self { + // SAFETY: `ZeroablePrimitive` guarantees that the size and bit + // validity of `.0` is such that this transmute is sound. + unsafe { intrinsics::transmute_unchecked(nonzero) } + } +} + #[stable(feature = "nonzero_bitor", since = "1.45.0")] impl BitOr for NonZero where