Skip to content

Commit 3f1192c

Browse files
committed
Provide documentation for Default impls
For the most part, the `Default` impls are pretty obvious as far as what we expect them to return, but I think it's better to explicitly state what's going to be returned in the documentation instead of relying on the user to make assumptions/look at the source.
1 parent cfea8ec commit 3f1192c

File tree

21 files changed

+26
-0
lines changed

21 files changed

+26
-0
lines changed

src/liballoc/arc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ impl<T: fmt::Debug> fmt::Debug for Arc<T> {
606606

607607
#[stable(feature = "rust1", since = "1.0.0")]
608608
impl<T: Default + Sync + Send> Default for Arc<T> {
609+
/// Creates a new `Arc` using `Arc::new` with the `Default` value of `T`
609610
#[stable(feature = "rust1", since = "1.0.0")]
610611
fn default() -> Arc<T> { Arc::new(Default::default()) }
611612
}

src/liballoc/boxed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,14 @@ pub unsafe fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T {
150150

151151
#[stable(feature = "rust1", since = "1.0.0")]
152152
impl<T: Default> Default for Box<T> {
153+
/// Creates a new `Box<T>` by `box`ing the `Default` value of `T`
153154
#[stable(feature = "rust1", since = "1.0.0")]
154155
fn default() -> Box<T> { box Default::default() }
155156
}
156157

157158
#[stable(feature = "rust1", since = "1.0.0")]
158159
impl<T> Default for Box<[T]> {
160+
/// Creates a new `Box<[T]>` by `box`ing an empty slice
159161
#[stable(feature = "rust1", since = "1.0.0")]
160162
fn default() -> Box<[T]> { Box::<[T; 0]>::new([]) }
161163
}

src/libcollections/binary_heap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub struct BinaryHeap<T> {
171171

172172
#[stable(feature = "rust1", since = "1.0.0")]
173173
impl<T: Ord> Default for BinaryHeap<T> {
174+
/// Creates a new `BinaryHeap` using `BinaryHeap::new`
174175
#[inline]
175176
fn default() -> BinaryHeap<T> { BinaryHeap::new() }
176177
}

src/libcollections/bit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ impl BitVec {
918918

919919
#[stable(feature = "rust1", since = "1.0.0")]
920920
impl Default for BitVec {
921+
/// Creates a new `BitVec` using `BitVec::new`
921922
#[inline]
922923
fn default() -> BitVec { BitVec::new() }
923924
}
@@ -1128,6 +1129,7 @@ pub struct BitSet {
11281129

11291130
#[stable(feature = "rust1", since = "1.0.0")]
11301131
impl Default for BitSet {
1132+
/// Creates a new `BitSet` using `BitSet::new`
11311133
#[inline]
11321134
fn default() -> BitSet { BitSet::new() }
11331135
}

src/libcollections/btree/map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ impl<K: Hash, V: Hash> Hash for BTreeMap<K, V> {
863863

864864
#[stable(feature = "rust1", since = "1.0.0")]
865865
impl<K: Ord, V> Default for BTreeMap<K, V> {
866+
/// Creates a new `BTreeMap` using `BTreeMap::new`
866867
#[stable(feature = "rust1", since = "1.0.0")]
867868
fn default() -> BTreeMap<K, V> {
868869
BTreeMap::new()

src/libcollections/btree/set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ impl<T: Ord> Extend<T> for BTreeSet<T> {
512512

513513
#[stable(feature = "rust1", since = "1.0.0")]
514514
impl<T: Ord> Default for BTreeSet<T> {
515+
/// Creates a new `BTreeSet` using `BTreeSet::new`
515516
#[stable(feature = "rust1", since = "1.0.0")]
516517
fn default() -> BTreeSet<T> {
517518
BTreeSet::new()

src/libcollections/linked_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl<T> LinkedList<T> {
212212

213213
#[stable(feature = "rust1", since = "1.0.0")]
214214
impl<T> Default for LinkedList<T> {
215+
/// Creates a new `LinkedList` using `LinkedList::new`
215216
#[inline]
216217
#[stable(feature = "rust1", since = "1.0.0")]
217218
fn default() -> LinkedList<T> { LinkedList::new() }

src/libcollections/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ impl Str for String {
811811

812812
#[stable(feature = "rust1", since = "1.0.0")]
813813
impl Default for String {
814+
/// Creates a new `String` using `String::new`
814815
#[inline]
815816
#[stable(feature = "rust1", since = "1.0.0")]
816817
fn default() -> String {

src/libcollections/vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,7 @@ impl<T> Drop for Vec<T> {
15991599

16001600
#[stable(feature = "rust1", since = "1.0.0")]
16011601
impl<T> Default for Vec<T> {
1602+
/// Creates a new `Vec` using `Vec::new`
16021603
#[stable(feature = "rust1", since = "1.0.0")]
16031604
fn default() -> Vec<T> {
16041605
Vec::new()

src/libcollections/vec_deque.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl<T> Drop for VecDeque<T> {
8383

8484
#[stable(feature = "rust1", since = "1.0.0")]
8585
impl<T> Default for VecDeque<T> {
86+
/// Creates a new `VecDeque` using `VecDeque::new`
8687
#[inline]
8788
fn default() -> VecDeque<T> { VecDeque::new() }
8889
}

0 commit comments

Comments
 (0)