Skip to content

Commit 1b4fe4e

Browse files
committed
Fix following rust-lang/rust#61780
1 parent 1dcddda commit 1b4fe4e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/table.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::alloc::{handle_alloc_error, Alloc, Global, Layout, LayoutErr};
12-
use std::collections::CollectionAllocErr;
12+
use std::collections::TryReserveError;
1313
use std::hash::{BuildHasher, Hash, Hasher};
1414
use std::marker;
1515
use std::mem;
@@ -679,7 +679,7 @@ impl<K, V> RawTable<K, V> {
679679
unsafe fn new_uninitialized_internal(
680680
capacity: usize,
681681
fallibility: Fallibility,
682-
) -> Result<RawTable<K, V>, CollectionAllocErr> {
682+
) -> Result<RawTable<K, V>, TryReserveError> {
683683
if capacity == 0 {
684684
return Ok(RawTable {
685685
size: 0,
@@ -694,10 +694,16 @@ impl<K, V> RawTable<K, V> {
694694
// we just allocate a single array, and then have the subarrays
695695
// point into it.
696696
let (layout, _) = calculate_layout::<K, V>(capacity)?;
697-
let buffer = Global.alloc(layout).map_err(|e| match fallibility {
698-
Infallible => handle_alloc_error(layout),
699-
Fallible => e,
700-
})?;
697+
let buffer = Global
698+
.alloc(layout)
699+
.map_err(|e| match fallibility {
700+
Infallible => handle_alloc_error(layout),
701+
Fallible => e,
702+
})
703+
.map_err(|_alloc_err| TryReserveError::AllocError {
704+
layout: layout,
705+
non_exhaustive: (),
706+
})?;
701707

702708
Ok(RawTable {
703709
capacity_mask: capacity.wrapping_sub(1),
@@ -711,8 +717,8 @@ impl<K, V> RawTable<K, V> {
711717
/// at the very least, set every hash to EMPTY_BUCKET.
712718
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
713719
match Self::new_uninitialized_internal(capacity, Infallible) {
714-
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
715-
Err(CollectionAllocErr::AllocErr) => unreachable!(),
720+
Err(TryReserveError::CapacityOverflow) => panic!("capacity overflow"),
721+
Err(TryReserveError::AllocError { .. }) => unreachable!(),
716722
Ok(table) => table,
717723
}
718724
}
@@ -733,7 +739,7 @@ impl<K, V> RawTable<K, V> {
733739
fn new_internal(
734740
capacity: usize,
735741
fallibility: Fallibility,
736-
) -> Result<RawTable<K, V>, CollectionAllocErr> {
742+
) -> Result<RawTable<K, V>, TryReserveError> {
737743
unsafe {
738744
let ret = RawTable::new_uninitialized_internal(capacity, fallibility)?;
739745
if capacity > 0 {
@@ -744,18 +750,18 @@ impl<K, V> RawTable<K, V> {
744750
}
745751

746752
/// Tries to create a new raw table from a given capacity. If it cannot allocate,
747-
/// it returns with AllocErr.
753+
/// it returns with AllocError.
748754
#[allow(unused)]
749-
pub fn try_new(capacity: usize) -> Result<RawTable<K, V>, CollectionAllocErr> {
755+
pub fn try_new(capacity: usize) -> Result<RawTable<K, V>, TryReserveError> {
750756
Self::new_internal(capacity, Fallible)
751757
}
752758

753759
/// Creates a new raw table from a given capacity. All buckets are
754760
/// initially empty.
755761
pub fn new(capacity: usize) -> RawTable<K, V> {
756762
match Self::new_internal(capacity, Infallible) {
757-
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
758-
Err(CollectionAllocErr::AllocErr) => unreachable!(),
763+
Err(TryReserveError::CapacityOverflow) => panic!("capacity overflow"),
764+
Err(TryReserveError::AllocError { .. }) => unreachable!(),
759765
Ok(table) => table,
760766
}
761767
}

0 commit comments

Comments
 (0)