about summary refs log tree commit diff
path: root/src/liballoc/allocator.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-03-15 08:18:58 +0000
committerbors <bors@rust-lang.org>2018-03-15 08:18:58 +0000
commita4af6f089b2836530f31b6b839bde7cea8ae0b8a (patch)
tree97697f1b86297947058e61e93b01881e616c0a01 /src/liballoc/allocator.rs
parent5ebf74851d685f75abec7ef4e805f75fc301460c (diff)
parent06057d9143bc42f82c35b20c5c26fbfce58abc95 (diff)
downloadrust-a4af6f089b2836530f31b6b839bde7cea8ae0b8a.tar.gz
rust-a4af6f089b2836530f31b6b839bde7cea8ae0b8a.zip
Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](https://github.com/rust-lang/rust/issues/48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.
Diffstat (limited to 'src/liballoc/allocator.rs')
-rw-r--r--src/liballoc/allocator.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs
index 55e8c0b430f..fdc4efc66b9 100644
--- a/src/liballoc/allocator.rs
+++ b/src/liballoc/allocator.rs
@@ -373,6 +373,24 @@ impl fmt::Display for CannotReallocInPlace {
     }
 }
 
+/// Augments `AllocErr` with a CapacityOverflow variant.
+#[derive(Clone, PartialEq, Eq, Debug)]
+#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
+pub enum CollectionAllocErr {
+    /// 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(AllocErr),
+}
+
+#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
+impl From<AllocErr> for CollectionAllocErr {
+    fn from(err: AllocErr) -> Self {
+        CollectionAllocErr::AllocErr(err)
+    }
+}
+
 /// An implementation of `Alloc` can allocate, reallocate, and
 /// deallocate arbitrary blocks of data described via `Layout`.
 ///