From 1b4fe4eff9ac3b82eecdffa8fb878b402887c6f9 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 30 Aug 2019 14:17:23 -0400 Subject: [PATCH] Fix following rust-lang/rust#61780 --- src/table.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/table.rs b/src/table.rs index 14428cf..46c8938 100644 --- a/src/table.rs +++ b/src/table.rs @@ -9,7 +9,7 @@ // except according to those terms. use std::alloc::{handle_alloc_error, Alloc, Global, Layout, LayoutErr}; -use std::collections::CollectionAllocErr; +use std::collections::TryReserveError; use std::hash::{BuildHasher, Hash, Hasher}; use std::marker; use std::mem; @@ -679,7 +679,7 @@ impl RawTable { unsafe fn new_uninitialized_internal( capacity: usize, fallibility: Fallibility, - ) -> Result, CollectionAllocErr> { + ) -> Result, TryReserveError> { if capacity == 0 { return Ok(RawTable { size: 0, @@ -694,10 +694,16 @@ impl RawTable { // we just allocate a single array, and then have the subarrays // point into it. let (layout, _) = calculate_layout::(capacity)?; - let buffer = Global.alloc(layout).map_err(|e| match fallibility { - Infallible => handle_alloc_error(layout), - Fallible => e, - })?; + let buffer = Global + .alloc(layout) + .map_err(|e| match fallibility { + Infallible => handle_alloc_error(layout), + Fallible => e, + }) + .map_err(|_alloc_err| TryReserveError::AllocError { + layout: layout, + non_exhaustive: (), + })?; Ok(RawTable { capacity_mask: capacity.wrapping_sub(1), @@ -711,8 +717,8 @@ impl RawTable { /// at the very least, set every hash to EMPTY_BUCKET. unsafe fn new_uninitialized(capacity: usize) -> RawTable { match Self::new_uninitialized_internal(capacity, Infallible) { - Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"), - Err(CollectionAllocErr::AllocErr) => unreachable!(), + Err(TryReserveError::CapacityOverflow) => panic!("capacity overflow"), + Err(TryReserveError::AllocError { .. }) => unreachable!(), Ok(table) => table, } } @@ -733,7 +739,7 @@ impl RawTable { fn new_internal( capacity: usize, fallibility: Fallibility, - ) -> Result, CollectionAllocErr> { + ) -> Result, TryReserveError> { unsafe { let ret = RawTable::new_uninitialized_internal(capacity, fallibility)?; if capacity > 0 { @@ -744,9 +750,9 @@ impl RawTable { } /// Tries to create a new raw table from a given capacity. If it cannot allocate, - /// it returns with AllocErr. + /// it returns with AllocError. #[allow(unused)] - pub fn try_new(capacity: usize) -> Result, CollectionAllocErr> { + pub fn try_new(capacity: usize) -> Result, TryReserveError> { Self::new_internal(capacity, Fallible) } @@ -754,8 +760,8 @@ impl RawTable { /// initially empty. pub fn new(capacity: usize) -> RawTable { match Self::new_internal(capacity, Infallible) { - Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"), - Err(CollectionAllocErr::AllocErr) => unreachable!(), + Err(TryReserveError::CapacityOverflow) => panic!("capacity overflow"), + Err(TryReserveError::AllocError { .. }) => unreachable!(), Ok(table) => table, } }