Skip to content

Commit

Permalink
Move core::alloc::CollectionAllocErr to alloc::collections
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jun 29, 2018
1 parent 121b57b commit b0547ce
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 36 deletions.
29 changes: 29 additions & 0 deletions src/liballoc/collections/mod.rs
Expand Up @@ -51,6 +51,35 @@ pub use self::linked_list::LinkedList;
#[doc(no_inline)]
pub use self::vec_deque::VecDeque;

use alloc::{AllocErr, LayoutErr};

/// 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,
}

#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
impl From<AllocErr> for CollectionAllocErr {
#[inline]
fn from(AllocErr: AllocErr) -> Self {
CollectionAllocErr::AllocErr
}
}

#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
impl From<LayoutErr> for CollectionAllocErr {
#[inline]
fn from(_: LayoutErr) -> Self {
CollectionAllocErr::CapacityOverflow
}
}

/// An intermediate trait for specialization of `Extend`.
#[doc(hidden)]
trait SpecExtend<I: IntoIterator> {
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/vec_deque.rs
Expand Up @@ -30,7 +30,7 @@ use core::slice;
use core::hash::{Hash, Hasher};
use core::cmp;

use alloc::CollectionAllocErr;
use collections::CollectionAllocErr;
use raw_vec::RawVec;
use vec::Vec;

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/raw_vec.rs
Expand Up @@ -18,8 +18,8 @@ use core::ptr::{self, NonNull, Unique};
use core::slice;

use alloc::{Alloc, Layout, Global, handle_alloc_error};
use alloc::CollectionAllocErr;
use alloc::CollectionAllocErr::*;
use collections::CollectionAllocErr;
use collections::CollectionAllocErr::*;
use boxed::Box;

/// A low-level utility for more ergonomically allocating, reallocating, and deallocating
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/string.rs
Expand Up @@ -66,7 +66,7 @@ use core::ptr;
use core::str::pattern::Pattern;
use core::str::lossy;

use alloc::CollectionAllocErr;
use collections::CollectionAllocErr;
use borrow::{Cow, ToOwned};
use boxed::Box;
use str::{self, from_boxed_utf8_unchecked, FromStr, Utf8Error, Chars};
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/vec.rs
Expand Up @@ -80,7 +80,7 @@ use core::ptr;
use core::ptr::NonNull;
use core::slice;

use alloc::CollectionAllocErr;
use collections::CollectionAllocErr;
use borrow::ToOwned;
use borrow::Cow;
use boxed::Box;
Expand Down
28 changes: 0 additions & 28 deletions src/libcore/alloc.rs
Expand Up @@ -385,34 +385,6 @@ impl fmt::Display for CannotReallocInPlace {
}
}

/// Augments `AllocErr` with a CapacityOverflow variant.
// FIXME: should this be in libcore or liballoc?
#[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,
}

#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
impl From<AllocErr> for CollectionAllocErr {
#[inline]
fn from(AllocErr: AllocErr) -> Self {
CollectionAllocErr::AllocErr
}
}

#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
impl From<LayoutErr> for CollectionAllocErr {
#[inline]
fn from(_: LayoutErr) -> Self {
CollectionAllocErr::CapacityOverflow
}
}

/// A memory allocator that can be registered as the standard library’s default
/// though the `#[global_allocator]` attributes.
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/collections/hash/map.rs
Expand Up @@ -11,7 +11,7 @@
use self::Entry::*;
use self::VacantEntryState::*;

use alloc::CollectionAllocErr;
use collections::CollectionAllocErr;
use cell::Cell;
use borrow::Borrow;
use cmp::max;
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/collections/hash/table.rs
Expand Up @@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use alloc::{Global, Alloc, Layout, LayoutErr, CollectionAllocErr, handle_alloc_error};
use alloc::{Global, Alloc, Layout, LayoutErr, handle_alloc_error};
use collections::CollectionAllocErr;
use hash::{BuildHasher, Hash, Hasher};
use marker;
use mem::{size_of, needs_drop};
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/collections/mod.rs
Expand Up @@ -438,7 +438,7 @@ pub use self::hash_map::HashMap;
pub use self::hash_set::HashSet;

#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
pub use alloc::CollectionAllocErr;
pub use alloc_crate::collections::CollectionAllocErr;

mod hash;

Expand Down

0 comments on commit b0547ce

Please sign in to comment.