1
Fork 0

Return Result instead of Option in alloc::Layout constructors

This commit is contained in:
Simon Sapin 2018-04-04 16:03:46 +02:00
parent f9c96d70bd
commit b017742136
4 changed files with 54 additions and 26 deletions

View file

@ -422,7 +422,7 @@ impl<T, A: Alloc> RawVec<T, A> {
// Nothing we can really do about these checks :(
let new_cap = used_cap.checked_add(needed_extra_cap).ok_or(CapacityOverflow)?;
let new_layout = Layout::array::<T>(new_cap).ok_or(CapacityOverflow)?;
let new_layout = Layout::array::<T>(new_cap).map_err(|_| CapacityOverflow)?;
alloc_guard(new_layout.size())?;
@ -530,7 +530,7 @@ impl<T, A: Alloc> RawVec<T, A> {
}
let new_cap = self.amortized_new_size(used_cap, needed_extra_cap)?;
let new_layout = Layout::array::<T>(new_cap).ok_or(CapacityOverflow)?;
let new_layout = Layout::array::<T>(new_cap).map_err(|_| CapacityOverflow)?;
// FIXME: may crash and burn on over-reserve
alloc_guard(new_layout.size())?;