@@ -216,18 +216,16 @@ impl Global {
216216
217217 #[ inline]
218218 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
219- fn deallocate_impl_runtime ( ptr : NonNull < u8 > , layout : Layout ) {
220- if layout. size ( ) != 0 {
221- // SAFETY:
222- // * We have checked that `layout` is non-zero in size.
223- // * The caller is obligated to provide a layout that "fits", and in this case,
224- // "fit" always means a layout that is equal to the original, because our
225- // `allocate()`, `grow()`, and `shrink()` implementations never returns a larger
226- // allocation than requested.
227- // * Other conditions must be upheld by the caller, as per `Allocator::deallocate()`'s
228- // safety documentation.
229- unsafe { dealloc_nonnull ( ptr, layout) }
230- }
219+ fn deallocate_nonzero_impl_runtime ( ptr : NonNull < u8 > , layout : Layout ) {
220+ // SAFETY:
221+ // * The caller provided a `layout` that is non-zero in size.
222+ // * The caller is obligated to provide a layout that "fits", and in this case,
223+ // "fit" always means a layout that is equal to the original, because our
224+ // `allocate()`, `grow()`, and `shrink()` implementations never returns a larger
225+ // allocation than requested.
226+ // * Other conditions must be upheld by the caller, as per `Allocator::deallocate()`'s
227+ // safety documentation.
228+ unsafe { dealloc_nonnull ( ptr, layout) }
231229 }
232230
233231 // SAFETY: Same as `Allocator::grow`
@@ -340,11 +338,11 @@ impl Global {
340338 #[ inline]
341339 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
342340 #[ rustc_const_unstable( feature = "const_heap" , issue = "79597" ) ]
343- const unsafe fn deallocate_impl ( & self , ptr : NonNull < u8 > , layout : Layout ) {
341+ const unsafe fn deallocate_nonzero_impl ( & self , ptr : NonNull < u8 > , layout : Layout ) {
344342 core:: intrinsics:: const_eval_select (
345343 ( ptr, layout) ,
346- Global :: deallocate_impl_const ,
347- Global :: deallocate_impl_runtime ,
344+ Global :: deallocate_nonzero_impl_const ,
345+ Global :: deallocate_nonzero_impl_runtime ,
348346 )
349347 }
350348
@@ -405,12 +403,10 @@ impl Global {
405403 #[ inline]
406404 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
407405 #[ rustc_const_unstable( feature = "const_heap" , issue = "79597" ) ]
408- const fn deallocate_impl_const ( ptr : NonNull < u8 > , layout : Layout ) {
409- if layout. size ( ) != 0 {
410- // SAFETY: We checked for nonzero size; other preconditions must be upheld by caller.
411- unsafe {
412- core:: intrinsics:: const_deallocate ( ptr. as_ptr ( ) , layout. size ( ) , layout. align ( ) ) ;
413- }
406+ const fn deallocate_nonzero_impl_const ( ptr : NonNull < u8 > , layout : Layout ) {
407+ // SAFETY: all conditions must be upheld by the caller
408+ unsafe {
409+ core:: intrinsics:: const_deallocate ( ptr. as_ptr ( ) , layout. size ( ) , layout. align ( ) ) ;
414410 }
415411 }
416412
@@ -434,7 +430,7 @@ impl Global {
434430 ) ;
435431 }
436432 unsafe {
437- self . deallocate_impl ( ptr, old_layout) ;
433+ self . deallocate ( ptr, old_layout) ;
438434 }
439435 Ok ( new_ptr)
440436 }
@@ -458,8 +454,17 @@ unsafe impl const Allocator for Global {
458454 #[ inline]
459455 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
460456 unsafe fn deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) {
457+ if layout. size ( ) != 0 {
458+ // SAFETY: We checked for nonzero size; other preconditions must be upheld by caller.
459+ unsafe { self . deallocate_nonzero_size ( ptr, layout) }
460+ }
461+ }
462+
463+ #[ inline]
464+ #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
465+ unsafe fn deallocate_nonzero_size ( & self , ptr : NonNull < u8 > , layout : Layout ) {
461466 // SAFETY: all conditions must be upheld by the caller
462- unsafe { self . deallocate_impl ( ptr, layout) }
467+ unsafe { self . deallocate_nonzero_impl ( ptr, layout) }
463468 }
464469
465470 #[ inline]
0 commit comments