diff --git a/alloc/src/alloc.rs b/alloc/src/alloc.rs index a91659b6de5ad..98402a4620158 100644 --- a/alloc/src/alloc.rs +++ b/alloc/src/alloc.rs @@ -155,11 +155,14 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 /// # Examples /// /// ``` -/// use std::alloc::{alloc_zeroed, dealloc, Layout}; +/// use std::alloc::{alloc_zeroed, dealloc, handle_alloc_error, Layout}; /// /// unsafe { /// let layout = Layout::new::(); /// let ptr = alloc_zeroed(layout); +/// if ptr.is_null() { +/// handle_alloc_error(layout); +/// } /// /// assert_eq!(*(ptr as *mut u16), 0); ///