diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index a0d716fb5740..3d84e910fe66 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2553,6 +2553,14 @@ impl NonNull { pub unsafe fn as_mut(&mut self) -> &mut T { &mut *self.as_ptr() } + + /// Cast to a pointer of another type + #[unstable(feature = "nonnull_cast", issue = "47653")] + pub fn cast(self) -> NonNull { + unsafe { + NonNull::new_unchecked(self.as_ptr() as *mut U) + } + } } #[stable(feature = "nonnull", since = "1.25.0")]