diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 032df7f5a80..87c8674af0d 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -173,8 +173,14 @@ impl NonNull { /// /// let mut x = 0u32; /// let ptr = unsafe { NonNull::new_unchecked(&mut x as *mut _) }; + /// ``` /// - /// // NEVER DO THAT!!! + /// *Incorrect* usage of this function: + /// + /// ```rust,no_run + /// use std::ptr::NonNull; + /// + /// // NEVER DO THAT!!! This is undefined behavior. ⚠️ /// let ptr = unsafe { NonNull::::new_unchecked(std::ptr::null_mut()) }; /// ``` #[stable(feature = "nonnull", since = "1.25.0")]