diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 6477858f14b..e8d563e3895 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -248,6 +248,9 @@ pub struct Box< #[cfg(not(no_global_oom_handling))] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] const fn box_new_uninit(layout: Layout) -> *mut u8 { + if layout.size() == 0 { + return layout.dangling_ptr().as_ptr(); + } match Global.allocate(layout) { Ok(ptr) => ptr.as_mut_ptr(), Err(_) => handle_alloc_error(layout),