Skip to content

Commit

Permalink
std: Second pass stabilization of default
Browse files Browse the repository at this point in the history
This commit performs a second pass stabilization of the `std::default` module.
The module was already marked `#[stable]`, and the inheritance of `#[stable]`
was removed since this attribute was applied. This commit adds the `#[stable]`
attribute to the trait definition and one method name, along with all
implementations found in the standard distribution.
  • Loading branch information
alexcrichton committed Dec 16, 2014
1 parent 23bae85 commit 9021f61
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/liballoc/arc.rs
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
Expand Up @@ -44,11 +44,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
Expand Up @@ -447,6 +447,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
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
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
Expand Up @@ -836,7 +836,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
Expand Up @@ -436,7 +436,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
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/hash/sip.rs
Expand Up @@ -204,8 +204,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/libcollections/ring_buf.rs
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
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
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
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
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
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
Expand Up @@ -1322,6 +1322,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
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
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 @@ -349,8 +350,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
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
1 change: 1 addition & 0 deletions src/libcore/option.rs
Expand Up @@ -760,6 +760,7 @@ impl<T> AsSlice<T> for Option<T> {

#[stable]
impl<T> Default for Option<T> {
#[stable]
#[inline]
fn default() -> Option<T> { None }
}
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/slice.rs
Expand Up @@ -1044,8 +1044,9 @@ impl<'a, T, Sized? U: AsSlice<T>> AsSlice<T> for &'a mut U {
fn as_slice<'a>(&'a self) -> &'a [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
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
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
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
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
Expand Up @@ -610,7 +610,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
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
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 9021f61

Please sign in to comment.