@@ -531,7 +531,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
531
531
#[ inline]
532
532
#[ cfg( feature = "raw" ) ]
533
533
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 )
535
535
}
536
536
537
537
/// Returns the index of a bucket from a `Bucket`.
@@ -1589,6 +1589,11 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1589
1589
1590
1590
#[ inline]
1591
1591
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
+
1592
1597
// Avoid `Option::unwrap_or_else` because it bloats LLVM IR.
1593
1598
let ( layout, ctrl_offset) = match table_layout. calculate_layout_for ( self . buckets ( ) ) {
1594
1599
Some ( lco) => lco,
@@ -1600,6 +1605,15 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1600
1605
)
1601
1606
}
1602
1607
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
+
1603
1617
/// Marks all table buckets as empty without dropping their contents.
1604
1618
#[ inline]
1605
1619
fn clear_no_drop ( & mut self ) {
0 commit comments