We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b3f4c31 commit 080a53aCopy full SHA for 080a53a
library/alloc/src/alloc.rs
@@ -70,11 +70,14 @@ pub use std::alloc::Global;
70
/// # Examples
71
///
72
/// ```
73
-/// use std::alloc::{alloc, dealloc, Layout};
+/// use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};
74
75
/// unsafe {
76
/// let layout = Layout::new::<u16>();
77
/// let ptr = alloc(layout);
78
+/// if ptr.is_null() {
79
+/// handle_alloc_error(layout);
80
+/// }
81
82
/// *(ptr as *mut u16) = 42;
83
/// assert_eq!(*(ptr as *mut u16), 42);
0 commit comments