@@ -531,7 +531,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
531531 #[ inline]
532532 #[ cfg( feature = "raw" ) ]
533533 pub fn allocation_info ( & self ) -> ( NonNull < u8 > , Layout ) {
534- self . table . allocation_info ( Self :: TABLE_LAYOUT )
534+ self . table . allocation_info_or_zero ( Self :: TABLE_LAYOUT )
535535 }
536536
537537 /// Returns the index of a bucket from a `Bucket`.
@@ -1589,6 +1589,11 @@ impl<A: Allocator + Clone> RawTableInner<A> {
15891589
15901590 #[ inline]
15911591 fn allocation_info ( & self , table_layout : TableLayout ) -> ( NonNull < u8 > , Layout ) {
1592+ debug_assert ! (
1593+ !self . is_empty_singleton( ) ,
1594+ "this function can only be called on non-empty tables"
1595+ ) ;
1596+
15921597 // Avoid `Option::unwrap_or_else` because it bloats LLVM IR.
15931598 let ( layout, ctrl_offset) = match table_layout. calculate_layout_for ( self . buckets ( ) ) {
15941599 Some ( lco) => lco,
@@ -1600,6 +1605,15 @@ impl<A: Allocator + Clone> RawTableInner<A> {
16001605 )
16011606 }
16021607
1608+ #[ cfg( feature = "raw" ) ]
1609+ fn allocation_info_or_zero ( & self , table_layout : TableLayout ) -> ( NonNull < u8 > , Layout ) {
1610+ if self . is_empty_singleton ( ) {
1611+ ( NonNull :: dangling ( ) , Layout :: new :: < ( ) > ( ) )
1612+ } else {
1613+ self . allocation_info ( table_layout)
1614+ }
1615+ }
1616+
16031617 /// Marks all table buckets as empty without dropping their contents.
16041618 #[ inline]
16051619 fn clear_no_drop ( & mut self ) {
0 commit comments