Rollup merge of #36396 - athulappadan:Default-docs, r=bluss

Documentation of what Default does for each type

Addresses #36265
I haven't changed the following types due to doubts:

1)src/libstd/ffi/c_str.rs
2)src/libcore/iter/sources.rs
3)src/libcore/hash/mod.rs
4)src/libcore/hash/mod.rs
5)src/librustc/middle/privacy.rs

r? @steveklabnik
This commit is contained in:
Guillaume Gomez 2016-09-14 17:15:37 +02:00 committed by GitHub
commit a89690ec00
30 changed files with 38 additions and 0 deletions

View File

@ -718,6 +718,7 @@ fn clone(&self) -> Weak<T> {
#[stable(feature = "downgraded_weak", since = "1.10.0")]
impl<T> Default for Weak<T> {
/// Constructs a new `Weak<T>` without an accompanying instance of T.
fn default() -> Weak<T> {
Weak::new()
}
@ -923,6 +924,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Arc<T> {
/// Creates a new `Arc<T>`, with the `Default` value for T.
fn default() -> Arc<T> {
Arc::new(Default::default())
}

View File

@ -290,6 +290,7 @@ pub fn into_raw(b: Box<T>) -> *mut T {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Box<T> {
/// Creates a `Box<T>`, with the `Default` value for T.
fn default() -> Box<T> {
box Default::default()
}

View File

@ -870,6 +870,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[stable(feature = "downgraded_weak", since = "1.10.0")]
impl<T> Default for Weak<T> {
/// Creates a new `Weak<T>`.
fn default() -> Weak<T> {
Weak::new()
}

View File

@ -263,6 +263,7 @@ fn clone_from(&mut self, source: &Self) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Default for BinaryHeap<T> {
/// Creates an empty `BinaryHeap<T>`.
#[inline]
fn default() -> BinaryHeap<T> {
BinaryHeap::new()

View File

@ -249,6 +249,7 @@ impl<'a, B: ?Sized> Default for Cow<'a, B>
where B: ToOwned,
<B as ToOwned>::Owned: Default
{
/// Creates an owned Cow<'a, B> with the default value for the contained owned value.
fn default() -> Cow<'a, B> {
Owned(<B as ToOwned>::Owned::default())
}

View File

@ -1667,6 +1667,7 @@ fn hash<H: Hasher>(&self, state: &mut H) {
}
impl<K: Ord, V> Default for BTreeMap<K, V> {
/// Creates an empty `BTreeMap<K, V>`.
fn default() -> BTreeMap<K, V> {
BTreeMap::new()
}

View File

@ -674,6 +674,7 @@ fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Default for BTreeSet<T> {
/// Makes an empty `BTreeSet<T>` with a reasonable choice of B.
fn default() -> BTreeSet<T> {
BTreeSet::new()
}

View File

@ -164,6 +164,7 @@ fn pop_back_node(&mut self) -> Option<Box<Node<T>>> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for LinkedList<T> {
/// Creates an empty `LinkedList<T>`.
#[inline]
fn default() -> Self {
Self::new()

View File

@ -1567,6 +1567,7 @@ fn ne(&self, other: &$lhs) -> bool { PartialEq::ne(&self[..], &other[..]) }
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for String {
/// Creates an empty `String`.
#[inline]
fn default() -> String {
String::new()

View File

@ -1652,6 +1652,7 @@ fn drop(&mut self) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Vec<T> {
/// Creates an empty `Vec<T>`.
fn default() -> Vec<T> {
Vec::new()
}

View File

@ -84,6 +84,7 @@ fn drop(&mut self) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for VecDeque<T> {
/// Creates an empty `VecDeque<T>`.
#[inline]
fn default() -> VecDeque<T> {
VecDeque::new()

View File

@ -317,6 +317,7 @@ fn clone(&self) -> Cell<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Default + Copy> Default for Cell<T> {
/// Creates a `Cell<T>`, with the `Default` value for T.
#[inline]
fn default() -> Cell<T> {
Cell::new(Default::default())
@ -758,6 +759,7 @@ fn clone(&self) -> RefCell<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Default> Default for RefCell<T> {
/// Creates a `RefCell<T>`, with the `Default` value for T.
#[inline]
fn default() -> RefCell<T> {
RefCell::new(Default::default())
@ -1139,6 +1141,7 @@ pub fn get(&self) -> *mut T {
#[stable(feature = "unsafe_cell_default", since = "1.9.0")]
impl<T: Default> Default for UnsafeCell<T> {
/// Creates an `UnsafeCell`, with the `Default` value for T.
fn default() -> UnsafeCell<T> {
UnsafeCell::new(Default::default())
}

View File

@ -333,6 +333,7 @@ fn clone(&self) -> Hasher<S> {
}
impl<S: Sip> Default for Hasher<S> {
/// Creates a `Hasher<S>` with the two initial keys set to 0.
#[inline]
fn default() -> Hasher<S> {
Hasher::new_with_keys(0, 0)

View File

@ -714,6 +714,7 @@ fn expect_failed(msg: &str) -> ! {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Option<T> {
/// Returns None.
#[inline]
fn default() -> Option<T> { None }
}

View File

@ -755,11 +755,13 @@ fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut [T] {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> Default for &'a [T] {
/// Creates an empty slice.
fn default() -> &'a [T] { &[] }
}
#[stable(feature = "mut_slice_default", since = "1.5.0")]
impl<'a, T> Default for &'a mut [T] {
/// Creates a mutable empty slice.
fn default() -> &'a mut [T] { &mut [] }
}

View File

@ -1987,5 +1987,6 @@ fn as_ref(&self) -> &[u8] {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Default for &'a str {
/// Creates an empty str
fn default() -> &'a str { "" }
}

View File

@ -95,6 +95,7 @@ pub struct AtomicBool {
#[cfg(target_has_atomic = "8")]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for AtomicBool {
/// Creates an `AtomicBool` initialised as false.
fn default() -> Self {
Self::new(false)
}
@ -117,6 +118,7 @@ pub struct AtomicPtr<T> {
#[cfg(target_has_atomic = "ptr")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for AtomicPtr<T> {
/// Creates a null `AtomicPtr<T>`.
fn default() -> AtomicPtr<T> {
AtomicPtr::new(::ptr::null_mut())
}

View File

@ -113,6 +113,7 @@ fn reseed(&mut self, rng: &mut R) {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for ReseedWithDefault {
/// Creates an instance of `ReseedWithDefault`.
fn default() -> ReseedWithDefault {
ReseedWithDefault
}
@ -137,6 +138,7 @@ fn next_u32(&mut self) -> u32 {
}
}
impl Default for Counter {
/// Constructs a `Counter` with initial value zero.
fn default() -> Counter {
Counter { i: 0 }
}

View File

@ -45,6 +45,7 @@ pub struct TargetDataLayout {
}
impl Default for TargetDataLayout {
/// Creates an instance of `TargetDataLayout`.
fn default() -> TargetDataLayout {
TargetDataLayout {
endian: Endian::Big,

View File

@ -35,6 +35,7 @@ pub fn FnvHashSet<V: Hash + Eq>() -> FnvHashSet<V> {
pub struct FnvHasher(u64);
impl Default for FnvHasher {
/// Creates a `FnvHasher`, with a 64-bit hex initial value.
#[inline]
fn default() -> FnvHasher {
FnvHasher(0xcbf29ce484222325)

View File

@ -109,6 +109,7 @@ enum SingleImports<'a> {
}
impl<'a> Default for SingleImports<'a> {
/// Creates a `SingleImports<'a>` of None type.
fn default() -> Self {
SingleImports::None
}

View File

@ -1218,6 +1218,7 @@ impl<K, V, S> Default for HashMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher + Default,
{
/// Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
fn default() -> HashMap<K, V, S> {
HashMap::with_hasher(Default::default())
}
@ -2026,6 +2027,7 @@ fn finish(&self) -> u64 {
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for RandomState {
/// Constructs a new `RandomState`.
#[inline]
fn default() -> RandomState {
RandomState::new()

View File

@ -665,6 +665,7 @@ impl<T, S> Default for HashSet<T, S>
where T: Eq + Hash,
S: BuildHasher + Default,
{
/// Creates an empty `HashSet<T, S>` with the `Default` value for the hasher.
fn default() -> HashSet<T, S> {
HashSet::with_hasher(Default::default())
}

View File

@ -361,6 +361,7 @@ fn default() -> &'a CStr {
#[stable(feature = "cstr_default", since = "1.10.0")]
impl Default for CString {
/// Creates an empty `CString`.
fn default() -> CString {
let a: &CStr = Default::default();
a.to_owned()

View File

@ -170,6 +170,7 @@ fn deref(&self) -> &OsStr {
#[stable(feature = "osstring_default", since = "1.9.0")]
impl Default for OsString {
/// Constructs an empty `OsString`.
#[inline]
fn default() -> OsString {
OsString::new()
@ -342,6 +343,7 @@ fn bytes(&self) -> &[u8] {
#[stable(feature = "osstring_default", since = "1.9.0")]
impl<'a> Default for &'a OsStr {
/// Creates an empty `OsStr`.
#[inline]
fn default() -> &'a OsStr {
OsStr::new("")

View File

@ -241,6 +241,7 @@ fn verify(&self, mutex: &sys_mutex::Mutex) {
#[stable(feature = "condvar_default", since = "1.9.0")]
impl Default for Condvar {
/// Creates a `Condvar` which is ready to be waited on and notified.
fn default() -> Condvar {
Condvar::new()
}

View File

@ -287,6 +287,7 @@ fn drop(&mut self) {
#[stable(feature = "mutex_default", since = "1.9.0")]
impl<T: ?Sized + Default> Default for Mutex<T> {
/// Creates a `Mutex<T>`, with the `Default` value for T.
fn default() -> Mutex<T> {
Mutex::new(Default::default())
}

View File

@ -311,6 +311,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[stable(feature = "rw_lock_default", since = "1.9.0")]
impl<T: Default> Default for RwLock<T> {
/// Creates a new `RwLock<T>`, with the `Default` value for T.
fn default() -> RwLock<T> {
RwLock::new(Default::default())
}

View File

@ -362,6 +362,7 @@ pub fn is_parameterized(&self) -> bool {
}
impl Default for Generics {
/// Creates an instance of `Generics`.
fn default() -> Generics {
Generics {
lifetimes: Vec::new(),

View File

@ -154,6 +154,7 @@ pub fn into_vec(self) -> Vec<T> {
}
impl<T> Default for P<[T]> {
/// Creates an empty `P<[T]>`.
fn default() -> P<[T]> {
P::new()
}