1
Fork 0

rollup merge of #19902: alexcrichton/second-pass-mem

This commit stabilizes the `mem` and `default` modules of std.
This commit is contained in:
Alex Crichton 2014-12-17 08:35:22 -08:00
commit 3369b33a20
30 changed files with 68 additions and 6 deletions

View file

@ -316,7 +316,9 @@ impl<T: fmt::Show> fmt::Show for Arc<T> {
} }
} }
#[stable]
impl<T: Default + Sync + Send> Default for Arc<T> { impl<T: Default + Sync + Send> Default for Arc<T> {
#[stable]
fn default() -> Arc<T> { Arc::new(Default::default()) } fn default() -> Arc<T> { Arc::new(Default::default()) }
} }

View file

@ -45,11 +45,15 @@ pub static HEAP: () = ();
#[unstable = "custom allocators will add an additional type parameter (with default)"] #[unstable = "custom allocators will add an additional type parameter (with default)"]
pub struct Box<T>(*mut T); pub struct Box<T>(*mut T);
#[stable]
impl<T: Default> Default for Box<T> { impl<T: Default> Default for Box<T> {
#[stable]
fn default() -> Box<T> { box Default::default() } fn default() -> Box<T> { box Default::default() }
} }
#[stable]
impl<T> Default for Box<[T]> { impl<T> Default for Box<[T]> {
#[stable]
fn default() -> Box<[T]> { box [] } fn default() -> Box<[T]> { box [] }
} }

View file

@ -448,6 +448,7 @@ impl<T: Default> Default for Rc<T> {
/// let x: Rc<int> = Default::default(); /// let x: Rc<int> = Default::default();
/// ``` /// ```
#[inline] #[inline]
#[stable]
fn default() -> Rc<T> { fn default() -> Rc<T> {
Rc::new(Default::default()) Rc::new(Default::default())
} }

View file

@ -172,8 +172,10 @@ pub struct BinaryHeap<T> {
data: Vec<T>, data: Vec<T>,
} }
#[stable]
impl<T: Ord> Default for BinaryHeap<T> { impl<T: Ord> Default for BinaryHeap<T> {
#[inline] #[inline]
#[stable]
fn default() -> BinaryHeap<T> { BinaryHeap::new() } fn default() -> BinaryHeap<T> { BinaryHeap::new() }
} }

View file

@ -824,8 +824,10 @@ pub fn from_fn<F>(len: uint, mut f: F) -> Bitv where F: FnMut(uint) -> bool {
bitv bitv
} }
#[stable]
impl Default for Bitv { impl Default for Bitv {
#[inline] #[inline]
#[stable]
fn default() -> Bitv { Bitv::new() } fn default() -> Bitv { Bitv::new() }
} }

View file

@ -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> { impl<K: Ord, V> Default for BTreeMap<K, V> {
#[stable]
fn default() -> BTreeMap<K, V> { fn default() -> BTreeMap<K, V> {
BTreeMap::new() BTreeMap::new()
} }

View file

@ -439,7 +439,9 @@ impl<T: Ord> Extend<T> for BTreeSet<T> {
} }
} }
#[stable]
impl<T: Ord> Default for BTreeSet<T> { impl<T: Ord> Default for BTreeSet<T> {
#[stable]
fn default() -> BTreeSet<T> { fn default() -> BTreeSet<T> {
BTreeSet::new() BTreeSet::new()
} }

View file

@ -192,8 +192,10 @@ impl<T> DList<T> {
} }
} }
#[stable]
impl<T> Default for DList<T> { impl<T> Default for DList<T> {
#[inline] #[inline]
#[stable]
fn default() -> DList<T> { DList::new() } fn default() -> DList<T> { DList::new() }
} }

View file

@ -68,7 +68,9 @@ impl<T> Drop for RingBuf<T> {
} }
} }
#[stable]
impl<T> Default for RingBuf<T> { impl<T> Default for RingBuf<T> {
#[stable]
#[inline] #[inline]
fn default() -> RingBuf<T> { RingBuf::new() } fn default() -> RingBuf<T> { RingBuf::new() }
} }

View file

@ -826,6 +826,7 @@ impl StrAllocating for String {
#[stable] #[stable]
impl Default for String { impl Default for String {
#[stable]
fn default() -> String { fn default() -> String {
String::new() String::new()
} }

View file

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

View file

@ -134,8 +134,10 @@ impl<T: Ord + Show> Show for TreeSet<T> {
} }
} }
#[stable]
impl<T: Ord> Default for TreeSet<T> { impl<T: Ord> Default for TreeSet<T> {
#[inline] #[inline]
#[stable]
fn default() -> TreeSet<T> { TreeSet::new() } fn default() -> TreeSet<T> { TreeSet::new() }
} }

View file

@ -150,8 +150,10 @@ impl<T: Show> Show for TrieMap<T> {
} }
} }
#[stable]
impl<T> Default for TrieMap<T> { impl<T> Default for TrieMap<T> {
#[inline] #[inline]
#[stable]
fn default() -> TrieMap<T> { TrieMap::new() } fn default() -> TrieMap<T> { TrieMap::new() }
} }

View file

@ -69,8 +69,10 @@ impl Show for TrieSet {
} }
} }
#[stable]
impl Default for TrieSet { impl Default for TrieSet {
#[inline] #[inline]
#[stable]
fn default() -> TrieSet { TrieSet::new() } fn default() -> TrieSet { TrieSet::new() }
} }

View file

@ -1330,6 +1330,7 @@ impl<T> Drop for Vec<T> {
#[stable] #[stable]
impl<T> Default for Vec<T> { impl<T> Default for Vec<T> {
#[stable]
fn default() -> Vec<T> { fn default() -> Vec<T> {
Vec::new() Vec::new()
} }

View file

@ -66,7 +66,9 @@ pub struct VecMap<V> {
v: Vec<Option<V>>, v: Vec<Option<V>>,
} }
#[stable]
impl<V> Default for VecMap<V> { impl<V> Default for VecMap<V> {
#[stable]
#[inline] #[inline]
fn default() -> VecMap<V> { VecMap::new() } fn default() -> VecMap<V> { VecMap::new() }
} }

View file

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

View file

@ -97,6 +97,7 @@
/// bar: f32, /// bar: f32,
/// } /// }
/// ``` /// ```
#[stable]
pub trait Default { pub trait Default {
/// Returns the "default value" for a type. /// Returns the "default value" for a type.
/// ///
@ -130,13 +131,16 @@ pub trait Default {
/// fn default() -> Kind { Kind::A } /// fn default() -> Kind { Kind::A }
/// } /// }
/// ``` /// ```
#[stable]
fn default() -> Self; fn default() -> Self;
} }
macro_rules! default_impl( macro_rules! default_impl(
($t:ty, $v:expr) => { ($t:ty, $v:expr) => {
#[stable]
impl Default for $t { impl Default for $t {
#[inline] #[inline]
#[stable]
fn default() -> $t { $v } fn default() -> $t { $v }
} }
} }

View file

@ -203,8 +203,10 @@ impl Clone for SipState {
} }
} }
#[stable]
impl Default for SipState { impl Default for SipState {
#[inline] #[inline]
#[stable]
fn default() -> SipState { fn default() -> SipState {
SipState::new() SipState::new()
} }

View file

@ -217,6 +217,7 @@ extern "rust-intrinsic" {
/// ///
/// `forget` is unsafe because the caller is responsible for /// `forget` is unsafe because the caller is responsible for
/// ensuring the argument is deallocated already. /// ensuring the argument is deallocated already.
#[stable]
pub fn forget<T>(_: T) -> (); pub fn forget<T>(_: T) -> ();
/// Unsafely transforms a value of one type into a value of another type. /// Unsafely transforms a value of one type into a value of another type.
@ -232,6 +233,7 @@ extern "rust-intrinsic" {
/// let v: &[u8] = unsafe { mem::transmute("L") }; /// let v: &[u8] = unsafe { mem::transmute("L") };
/// assert!(v == [76u8]); /// assert!(v == [76u8]);
/// ``` /// ```
#[stable]
pub fn transmute<T,U>(e: T) -> U; pub fn transmute<T,U>(e: T) -> U;
/// Gives the address for the return value of the enclosing function. /// Gives the address for the return value of the enclosing function.

View file

@ -13,9 +13,13 @@
//! This module contains functions for querying the size and alignment of //! This module contains functions for querying the size and alignment of
//! types, initializing and manipulating memory. //! types, initializing and manipulating memory.
#![stable]
use kinds::Sized;
use intrinsics; use intrinsics;
use ptr; use ptr;
#[stable]
pub use intrinsics::transmute; pub use intrinsics::transmute;
/// Moves a thing into the void. /// Moves a thing into the void.
@ -223,7 +227,8 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
#[inline] #[inline]
#[unstable = "this function may be removed in the future due to its \ #[unstable = "this function may be removed in the future due to its \
questionable utility"] 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) transmute(ptr)
} }
@ -231,7 +236,8 @@ pub unsafe fn copy_lifetime<'a, S, T:'a>(_ptr: &'a S, ptr: &T) -> &'a T {
#[inline] #[inline]
#[unstable = "this function may be removed in the future due to its \ #[unstable = "this function may be removed in the future due to its \
questionable utility"] questionable utility"]
pub unsafe fn copy_mut_lifetime<'a, S, T:'a>(_ptr: &'a mut S, pub unsafe fn copy_mut_lifetime<'a, Sized? S, Sized? T: 'a>(_ptr: &'a mut S,
ptr: &mut T) -> &'a mut T { ptr: &mut T)
-> &'a mut T {
transmute(ptr) transmute(ptr)
} }

View file

@ -763,6 +763,7 @@ impl<T> AsSlice<T> for Option<T> {
#[stable] #[stable]
impl<T> Default for Option<T> { impl<T> Default for Option<T> {
#[stable]
#[inline] #[inline]
#[stable] #[stable]
fn default() -> Option<T> { None } fn default() -> Option<T> { None }

View file

@ -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) } fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
} }
#[unstable = "waiting for DST"] #[stable]
impl<'a, T> Default for &'a [T] { impl<'a, T> Default for &'a [T] {
#[stable]
fn default() -> &'a [T] { &[] } fn default() -> &'a [T] { &[] }
} }

View file

@ -2349,7 +2349,9 @@ impl StrPrelude for str {
fn len(&self) -> uint { self.repr().len } fn len(&self) -> uint { self.repr().len }
} }
#[stable]
impl<'a> Default for &'a str { impl<'a> Default for &'a str {
#[stable]
fn default() -> &'a str { "" } fn default() -> &'a str { "" }
} }

View file

@ -182,6 +182,7 @@ macro_rules! tuple_impls {
#[stable] #[stable]
impl<$($T:Default),+> Default for ($($T,)+) { impl<$($T:Default),+> Default for ($($T,)+) {
#[stable]
#[inline] #[inline]
fn default() -> ($($T,)+) { fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+) ($({ let x: $T = Default::default(); x},)+)

View file

@ -142,7 +142,9 @@ impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
*rng = Default::default(); *rng = Default::default();
} }
} }
#[stable]
impl Default for ReseedWithDefault { impl Default for ReseedWithDefault {
#[stable]
fn default() -> ReseedWithDefault { ReseedWithDefault } fn default() -> ReseedWithDefault { ReseedWithDefault }
} }

View file

@ -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> { impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Default for HashMap<K, V, H> {
#[stable]
fn default() -> HashMap<K, V, H> { fn default() -> HashMap<K, V, H> {
HashMap::with_hasher(Default::default()) HashMap::with_hasher(Default::default())
} }

View file

@ -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> { impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Default for HashSet<T, H> {
#[stable]
fn default() -> HashSet<T, H> { fn default() -> HashSet<T, H> {
HashSet::with_hasher(Default::default()) HashSet::with_hasher(Default::default())
} }

View file

@ -95,7 +95,9 @@ impl Hasher<sip::SipState> for RandomSipHasher {
} }
} }
#[stable]
impl Default for RandomSipHasher { impl Default for RandomSipHasher {
#[stable]
#[inline] #[inline]
fn default() -> RandomSipHasher { fn default() -> RandomSipHasher {
RandomSipHasher::new() RandomSipHasher::new()

View file

@ -1911,7 +1911,9 @@ bitflags! {
} }
#[stable]
impl Default for FilePermission { impl Default for FilePermission {
#[stable]
#[inline] #[inline]
fn default() -> FilePermission { FilePermission::empty() } fn default() -> FilePermission { FilePermission::empty() }
} }