diff options
| author | Kornel <kornel@cloudflare.com> | 2021-07-23 16:40:43 +0100 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2021-07-24 22:25:08 +0100 |
| commit | a294aa8d3d7b73b7de60c629ae202194cffeb2f4 (patch) | |
| tree | 4c2da1977f0c2c835c5eeb726370cfc41eb0057e /library/std | |
| parent | bddb59cf07efcf6e606f16b87f85e3ecd2c1ca69 (diff) | |
Hide allocator details from TryReserveError
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/collections/hash/map.rs | 7 | ||||
| -rw-r--r-- | library/std/src/collections/hash/map/tests.rs | 6 | ||||
| -rw-r--r-- | library/std/src/collections/mod.rs | 6 | ||||
| -rw-r--r-- | library/std/src/lib.rs | 1 |
4 files changed, 15 insertions, 5 deletions
diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 4a5efab9055..66a2f2af773 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -10,6 +10,7 @@ use hashbrown::hash_map as base; use crate::borrow::Borrow; use crate::cell::Cell; use crate::collections::TryReserveError; +use crate::collections::TryReserveErrorKind; use crate::fmt::{self, Debug}; #[allow(deprecated)] use crate::hash::{BuildHasher, Hash, Hasher, SipHasher13}; @@ -2966,9 +2967,11 @@ fn map_entry<'a, K: 'a, V: 'a>(raw: base::RustcEntry<'a, K, V>) -> Entry<'a, K, #[inline] pub(super) fn map_try_reserve_error(err: hashbrown::TryReserveError) -> TryReserveError { match err { - hashbrown::TryReserveError::CapacityOverflow => TryReserveError::CapacityOverflow, + hashbrown::TryReserveError::CapacityOverflow => { + TryReserveErrorKind::CapacityOverflow.into() + } hashbrown::TryReserveError::AllocError { layout } => { - TryReserveError::AllocError { layout, non_exhaustive: () } + TryReserveErrorKind::AllocError { layout, non_exhaustive: () }.into() } } } diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs index 819be142227..73b7b7f6293 100644 --- a/library/std/src/collections/hash/map/tests.rs +++ b/library/std/src/collections/hash/map/tests.rs @@ -3,7 +3,7 @@ use super::HashMap; use super::RandomState; use crate::cell::RefCell; use rand::{thread_rng, Rng}; -use realstd::collections::TryReserveError::*; +use realstd::collections::TryReserveErrorKind::*; // https://github.com/rust-lang/rust/issues/62301 fn _assert_hashmap_is_unwind_safe() { @@ -821,12 +821,12 @@ fn test_try_reserve() { const MAX_USIZE: usize = usize::MAX; - if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE) { + if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE).map_err(|e| e.kind()) { } else { panic!("usize::MAX should trigger an overflow!"); } - if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_USIZE / 8) { + if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_USIZE / 8).map_err(|e| e.kind()) { } else { panic!("usize::MAX / 8 should trigger an OOM!") } diff --git a/library/std/src/collections/mod.rs b/library/std/src/collections/mod.rs index 8cda601edd1..130bb5cb2b3 100644 --- a/library/std/src/collections/mod.rs +++ b/library/std/src/collections/mod.rs @@ -422,6 +422,12 @@ pub use self::hash_set::HashSet; #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] pub use alloc_crate::collections::TryReserveError; +#[unstable( + feature = "try_reserve_kind", + reason = "Uncertain how much info should be exposed", + issue = "48043" +)] +pub use alloc_crate::collections::TryReserveErrorKind; mod hash; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index cfbfe7cc191..44e6c8fef1d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -325,6 +325,7 @@ #![feature(trace_macros)] #![feature(try_blocks)] #![feature(try_reserve)] +#![feature(try_reserve_kind)] #![feature(unboxed_closures)] #![feature(unsafe_cell_raw_get)] #![feature(unwind_attributes)] |
