diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2019-06-12 18:47:58 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2019-08-16 18:08:37 +0200 |
| commit | 59a340963fa5d8b5507d95cd015f7ca2855ba151 (patch) | |
| tree | 20ec73bf0c84a434d0d1192fc4216eb64e1d1161 /src/liballoc/collections | |
| parent | a92c29b2385f4999d4cd9ef7589f1fc07ef9cdfb (diff) | |
Add the Layout of the failed allocation to TryReserveError::AllocError
… and add a separately-unstable field to force non-exhaustive matching (`#[non_exhaustive]` is no implemented yet on enum variants) so that we have the option to later expose the allocator’s error value. CC https://github.com/rust-lang/wg-allocators/issues/23
Diffstat (limited to 'src/liballoc/collections')
| -rw-r--r-- | src/liballoc/collections/mod.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/liballoc/collections/mod.rs b/src/liballoc/collections/mod.rs index 48c3ed8a57d..f1f22fe48c5 100644 --- a/src/liballoc/collections/mod.rs +++ b/src/liballoc/collections/mod.rs @@ -41,25 +41,28 @@ pub use linked_list::LinkedList; #[doc(no_inline)] pub use vec_deque::VecDeque; -use crate::alloc::{AllocErr, LayoutErr}; +use crate::alloc::{Layout, LayoutErr}; -/// Augments `AllocErr` with a CapacityOverflow variant. +/// The error type for `try_reserve` methods. #[derive(Clone, PartialEq, Eq, Debug)] #[unstable(feature = "try_reserve", reason = "new API", issue="48043")] pub enum TryReserveError { /// Error due to the computed capacity exceeding the collection's maximum /// (usually `isize::MAX` bytes). CapacityOverflow, - /// Error due to the allocator (see the `AllocErr` type's docs). - AllocErr, -} -#[unstable(feature = "try_reserve", reason = "new API", issue="48043")] -impl From<AllocErr> for TryReserveError { - #[inline] - fn from(AllocErr: AllocErr) -> Self { - TryReserveError::AllocErr - } + /// The memory allocator returned an error + AllocError { + /// The layout of allocation request that failed + layout: Layout, + + #[doc(hidden)] + #[unstable(feature = "container_error_extra", issue = "0", reason = "\ + Enable exposing the allocator’s custom error value \ + if an associated type is added in the future: \ + https://github.com/rust-lang/wg-allocators/issues/23")] + non_exhaustive: (), + }, } #[unstable(feature = "try_reserve", reason = "new API", issue="48043")] |
