Skip to content

Commit

Permalink
rollup merge of rust-lang#19902: alexcrichton/second-pass-mem
Browse files Browse the repository at this point in the history
This commit stabilizes the `mem` and `default` modules of std.
  • Loading branch information
alexcrichton committed Dec 17, 2014
2 parents cada943 + 9021f61 commit 3369b33
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ impl<T: fmt::Show> fmt::Show for Arc<T> {
}
}

#[stable]
impl<T: Default + Sync + Send> Default for Arc<T> {
#[stable]
fn default() -> Arc<T> { Arc::new(Default::default()) }
}

Expand Down
4 changes: 4 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ pub static HEAP: () = ();
#[unstable = "custom allocators will add an additional type parameter (with default)"]
pub struct Box<T>(*mut T);

#[stable]
impl<T: Default> Default for Box<T> {
#[stable]
fn default() -> Box<T> { box Default::default() }
}

#[stable]
impl<T> Default for Box<[T]> {
#[stable]
fn default() -> Box<[T]> { box [] }
}

Expand Down
1 change: 1 addition & 0 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl<T: Default> Default for Rc<T> {
/// let x: Rc<int> = Default::default();
/// ```
#[inline]
#[stable]
fn default() -> Rc<T> {
Rc::new(Default::default())
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ pub struct BinaryHeap<T> {
data: Vec<T>,
}

#[stable]
impl<T: Ord> Default for BinaryHeap<T> {
#[inline]
#[stable]
fn default() -> BinaryHeap<T> { BinaryHeap::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,10 @@ pub fn from_fn<F>(len: uint, mut f: F) -> Bitv where F: FnMut(uint) -> bool {
bitv
}

#[stable]
impl Default for Bitv {
#[inline]
#[stable]
fn default() -> Bitv { Bitv::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ impl<S: Writer, K: Hash<S>, V: Hash<S>> Hash<S> for BTreeMap<K, V> {
}
}

#[stable]
impl<K: Ord, V> Default for BTreeMap<K, V> {
#[stable]
fn default() -> BTreeMap<K, V> {
BTreeMap::new()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ impl<T: Ord> Extend<T> for BTreeSet<T> {
}
}

#[stable]
impl<T: Ord> Default for BTreeSet<T> {
#[stable]
fn default() -> BTreeSet<T> {
BTreeSet::new()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ impl<T> DList<T> {
}
}

#[stable]
impl<T> Default for DList<T> {
#[inline]
#[stable]
fn default() -> DList<T> { DList::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl<T> Drop for RingBuf<T> {
}
}

#[stable]
impl<T> Default for RingBuf<T> {
#[stable]
#[inline]
fn default() -> RingBuf<T> { RingBuf::new() }
}
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ impl StrAllocating for String {

#[stable]
impl Default for String {
#[stable]
fn default() -> String {
String::new()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/tree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ impl<K: Ord + Show, V: Show> Show for TreeMap<K, V> {
}
}

#[stable]
impl<K: Ord, V> Default for TreeMap<K,V> {
#[inline]
#[stable]
fn default() -> TreeMap<K, V> { TreeMap::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/tree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ impl<T: Ord + Show> Show for TreeSet<T> {
}
}

#[stable]
impl<T: Ord> Default for TreeSet<T> {
#[inline]
#[stable]
fn default() -> TreeSet<T> { TreeSet::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/trie/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ impl<T: Show> Show for TrieMap<T> {
}
}

#[stable]
impl<T> Default for TrieMap<T> {
#[inline]
#[stable]
fn default() -> TrieMap<T> { TrieMap::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/trie/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ impl Show for TrieSet {
}
}

#[stable]
impl Default for TrieSet {
#[inline]
#[stable]
fn default() -> TrieSet { TrieSet::new() }
}

Expand Down
1 change: 1 addition & 0 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ impl<T> Drop for Vec<T> {

#[stable]
impl<T> Default for Vec<T> {
#[stable]
fn default() -> Vec<T> {
Vec::new()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ pub struct VecMap<V> {
v: Vec<Option<V>>,
}

#[stable]
impl<V> Default for VecMap<V> {
#[stable]
#[inline]
fn default() -> VecMap<V> { VecMap::new() }
}
Expand Down
6 changes: 4 additions & 2 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ impl<T:Copy> Clone for Cell<T> {
}
}

#[unstable]
#[stable]
impl<T:Default + Copy> Default for Cell<T> {
#[stable]
fn default() -> Cell<T> {
Cell::new(Default::default())
}
Expand Down Expand Up @@ -347,8 +348,9 @@ impl<T: Clone> Clone for RefCell<T> {
}
}

#[unstable]
#[stable]
impl<T:Default> Default for RefCell<T> {
#[stable]
fn default() -> RefCell<T> {
RefCell::new(Default::default())
}
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
/// bar: f32,
/// }
/// ```
#[stable]
pub trait Default {
/// Returns the "default value" for a type.
///
Expand Down Expand Up @@ -130,13 +131,16 @@ pub trait Default {
/// fn default() -> Kind { Kind::A }
/// }
/// ```
#[stable]
fn default() -> Self;
}

macro_rules! default_impl(
($t:ty, $v:expr) => {
#[stable]
impl Default for $t {
#[inline]
#[stable]
fn default() -> $t { $v }
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ impl Clone for SipState {
}
}

#[stable]
impl Default for SipState {
#[inline]
#[stable]
fn default() -> SipState {
SipState::new()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ extern "rust-intrinsic" {
///
/// `forget` is unsafe because the caller is responsible for
/// ensuring the argument is deallocated already.
#[stable]
pub fn forget<T>(_: T) -> ();

/// Unsafely transforms a value of one type into a value of another type.
Expand All @@ -232,6 +233,7 @@ extern "rust-intrinsic" {
/// let v: &[u8] = unsafe { mem::transmute("L") };
/// assert!(v == [76u8]);
/// ```
#[stable]
pub fn transmute<T,U>(e: T) -> U;

/// Gives the address for the return value of the enclosing function.
Expand Down
12 changes: 9 additions & 3 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
//! This module contains functions for querying the size and alignment of
//! types, initializing and manipulating memory.
#![stable]

use kinds::Sized;
use intrinsics;
use ptr;

#[stable]
pub use intrinsics::transmute;

/// Moves a thing into the void.
Expand Down Expand Up @@ -223,15 +227,17 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
#[inline]
#[unstable = "this function may be removed in the future due to its \
questionable utility"]
pub unsafe fn copy_lifetime<'a, S, T:'a>(_ptr: &'a S, ptr: &T) -> &'a T {
pub unsafe fn copy_lifetime<'a, Sized? S, Sized? T: 'a>(_ptr: &'a S,
ptr: &T) -> &'a T {
transmute(ptr)
}

/// Transforms lifetime of the second mutable pointer to match the first.
#[inline]
#[unstable = "this function may be removed in the future due to its \
questionable utility"]
pub unsafe fn copy_mut_lifetime<'a, S, T:'a>(_ptr: &'a mut S,
ptr: &mut T) -> &'a mut T {
pub unsafe fn copy_mut_lifetime<'a, Sized? S, Sized? T: 'a>(_ptr: &'a mut S,
ptr: &mut T)
-> &'a mut T {
transmute(ptr)
}
1 change: 1 addition & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ impl<T> AsSlice<T> for Option<T> {

#[stable]
impl<T> Default for Option<T> {
#[stable]
#[inline]
#[stable]
fn default() -> Option<T> { None }
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,9 @@ impl<'a, T, Sized? U: AsSlice<T>> AsSlice<T> for &'a mut U {
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
}

#[unstable = "waiting for DST"]
#[stable]
impl<'a, T> Default for &'a [T] {
#[stable]
fn default() -> &'a [T] { &[] }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,9 @@ impl StrPrelude for str {
fn len(&self) -> uint { self.repr().len }
}

#[stable]
impl<'a> Default for &'a str {
#[stable]
fn default() -> &'a str { "" }
}

1 change: 1 addition & 0 deletions src/libcore/tuple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ macro_rules! tuple_impls {

#[stable]
impl<$($T:Default),+> Default for ($($T,)+) {
#[stable]
#[inline]
fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+)
Expand Down
2 changes: 2 additions & 0 deletions src/librand/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
*rng = Default::default();
}
}
#[stable]
impl Default for ReseedWithDefault {
#[stable]
fn default() -> ReseedWithDefault { ReseedWithDefault }
}

Expand Down
2 changes: 2 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,9 @@ impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H>
}
}

#[stable]
impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Default for HashMap<K, V, H> {
#[stable]
fn default() -> HashMap<K, V, H> {
HashMap::with_hasher(Default::default())
}
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Extend<T> for HashSet<T, H> {
}
}

#[stable]
impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Default for HashSet<T, H> {
#[stable]
fn default() -> HashSet<T, H> {
HashSet::with_hasher(Default::default())
}
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl Hasher<sip::SipState> for RandomSipHasher {
}
}

#[stable]
impl Default for RandomSipHasher {
#[stable]
#[inline]
fn default() -> RandomSipHasher {
RandomSipHasher::new()
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,9 @@ bitflags! {
}


#[stable]
impl Default for FilePermission {
#[stable]
#[inline]
fn default() -> FilePermission { FilePermission::empty() }
}
Expand Down

0 comments on commit 3369b33

Please sign in to comment.