From b017742136a5d02b6ba0f2080e97d18a8bfeba4b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 4 Apr 2018 16:03:46 +0200 Subject: Return Result instead of Option in alloc::Layout constructors --- src/libstd/collections/hash/table.rs | 2 +- src/libstd/error.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index e9bdd4e7d07..50263705143 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -755,7 +755,7 @@ impl RawTable { } let buffer = Global.alloc(Layout::from_size_align(size, alignment) - .ok_or(CollectionAllocErr::CapacityOverflow)?)?; + .map_err(|_| CollectionAllocErr::CapacityOverflow)?)?; let hashes = buffer as *mut HashUint; diff --git a/src/libstd/error.rs b/src/libstd/error.rs index ec55a3c021a..3c209928d43 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -57,7 +57,7 @@ use cell; use char; use core::array; use fmt::{self, Debug, Display}; -use heap::{AllocErr, CannotReallocInPlace}; +use heap::{AllocErr, LayoutErr, CannotReallocInPlace}; use mem::transmute; use num; use str; @@ -247,6 +247,15 @@ impl Error for AllocErr { } } +#[unstable(feature = "allocator_api", + reason = "the precise API and guarantees it provides may be tweaked.", + issue = "32838")] +impl Error for LayoutErr { + fn description(&self) -> &str { + "invalid parameters to Layout::from_size_align" + } +} + #[unstable(feature = "allocator_api", reason = "the precise API and guarantees it provides may be tweaked.", issue = "32838")] -- cgit 1.4.1-3-g733a5