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
}

src/libcollections/vec_map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub struct OccupiedEntry<'a, V:'a> {
9494

9595
#[stable(feature = "rust1", since = "1.0.0")]
9696
impl<V> Default for VecMap<V> {
97+
/// Creates a new `VecMap` using `VecMap::new`
9798
#[stable(feature = "rust1", since = "1.0.0")]
9899
#[inline]
99100
fn default() -> VecMap<V> { VecMap::new() }

src/libcore/cell.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ impl<T:Copy> Clone for Cell<T> {
244244

245245
#[stable(feature = "rust1", since = "1.0.0")]
246246
impl<T:Default + Copy> Default for Cell<T> {
247+
/// Creates a new `Cell` using `Cell::new` with the `Default` value of `T`
247248
#[stable(feature = "rust1", since = "1.0.0")]
248249
fn default() -> Cell<T> {
249250
Cell::new(Default::default())
@@ -482,6 +483,7 @@ impl<T: Clone> Clone for RefCell<T> {
482483

483484
#[stable(feature = "rust1", since = "1.0.0")]
484485
impl<T:Default> Default for RefCell<T> {
486+
/// Creates a new `RefCell` using `RefCell::new` with the `Default` value of `T`
485487
#[stable(feature = "rust1", since = "1.0.0")]
486488
fn default() -> RefCell<T> {
487489
RefCell::new(Default::default())

src/libcore/hash/sip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl Clone for SipHasher {
223223

224224
#[stable(feature = "rust1", since = "1.0.0")]
225225
impl Default for SipHasher {
226+
/// Creates a new `SipHasher` using `SipHasher::new`
226227
fn default() -> SipHasher {
227228
SipHasher::new()
228229
}

src/libcore/option.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ impl<T> AsSlice<T> for Option<T> {
768768

769769
#[stable(feature = "rust1", since = "1.0.0")]
770770
impl<T> Default for Option<T> {
771+
/// Creates a new `Option` with value `None`
771772
#[inline]
772773
#[stable(feature = "rust1", since = "1.0.0")]
773774
fn default() -> Option<T> { None }

src/libcore/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ impl<'a, T, U: ?Sized + AsSlice<T>> AsSlice<T> for &'a mut U {
622622

623623
#[stable(feature = "rust1", since = "1.0.0")]
624624
impl<'a, T> Default for &'a [T] {
625+
/// Creates a new empty slice
625626
#[stable(feature = "rust1", since = "1.0.0")]
626627
fn default() -> &'a [T] { &[] }
627628
}

src/libcore/str/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ pub fn char_range_at_raw(bytes: &[u8], i: usize) -> (u32, usize) {
17021702

17031703
#[stable(feature = "rust1", since = "1.0.0")]
17041704
impl<'a> Default for &'a str {
1705+
/// Creates a new empty string slice
17051706
#[stable(feature = "rust1", since = "1.0.0")]
17061707
fn default() -> &'a str { "" }
17071708
}

src/libcore/tuple.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ macro_rules! tuple_impls {
112112

113113
#[stable(feature = "rust1", since = "1.0.0")]
114114
impl<$($T:Default),+> Default for ($($T,)+) {
115+
/// Creates a new tuple containing the `Default` value for each of the type
116+
/// parameters
115117
#[stable(feature = "rust1", since = "1.0.0")]
116118
#[inline]
117119
fn default() -> ($($T,)+) {

src/libstd/collections/hash/map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ impl<K, V, S> Default for HashMap<K, V, S>
12351235
where K: Eq + Hash,
12361236
S: HashState + Default,
12371237
{
1238+
/// Creates a new `HashMap` using `HashMap::with_hash_state` with the `Default` value for `S`
12381239
fn default() -> HashMap<K, V, S> {
12391240
HashMap::with_hash_state(Default::default())
12401241
}
@@ -1600,6 +1601,7 @@ impl HashState for RandomState {
16001601
reason = "hashing an hash maps may be altered")]
16011602
impl Default for RandomState {
16021603
#[inline]
1604+
/// Creates a new `RandomState` using `RandomState::new`
16031605
fn default() -> RandomState {
16041606
RandomState::new()
16051607
}

src/libstd/collections/hash/set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ impl<T, S> Default for HashSet<T, S>
640640
where T: Eq + Hash,
641641
S: HashState + Default,
642642
{
643+
/// Creates a new `HashSet` using `HashSet::with_hash_state` with the `Default` value for `S`
643644
#[stable(feature = "rust1", since = "1.0.0")]
644645
fn default() -> HashSet<T, S> {
645646
HashSet::with_hash_state(Default::default())

src/libstd/collections/hash/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ impl<H> Clone for DefaultState<H> {
5151
}
5252

5353
impl<H> Default for DefaultState<H> {
54+
/// Creates a new `DefaultState`
5455
fn default() -> DefaultState<H> { DefaultState(marker::PhantomData) }
5556
}

src/libsyntax/owned_slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl<T> Deref for OwnedSlice<T> {
6565
}
6666

6767
impl<T> Default for OwnedSlice<T> {
68+
/// Creates a new `OwnedSlice` using `OwnedSlice::empty`
6869
fn default() -> OwnedSlice<T> {
6970
OwnedSlice::empty()
7071
}

0 commit comments

Comments
 (0)