Skip to content

Commit 5a5736d

Browse files
authored
Auto merge of #36472 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 5 pull requests - Successful merges: #36334, #36335, #36363, #36374, #36467 - Failed merges:
2 parents 97b561a + e368cdd commit 5a5736d

File tree

40 files changed

+235
-111
lines changed

40 files changed

+235
-111
lines changed

src/doc/book/traits.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ won’t have its methods:
275275
[write]: ../std/io/trait.Write.html
276276

277277
```rust,ignore
278-
let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt");
278+
let mut f = std::fs::File::create("foo.txt").expect("Couldn’t create foo.txt");
279279
let buf = b"whatever"; // byte string literal. buf: &[u8; 8]
280280
let result = f.write(buf);
281281
# result.unwrap(); // ignore the error
@@ -294,7 +294,7 @@ We need to `use` the `Write` trait first:
294294
```rust,ignore
295295
use std::io::Write;
296296
297-
let mut f = std::fs::File::open("foo.txt").expect("Couldn’t open foo.txt");
297+
let mut f = std::fs::File::create("foo.txt").expect("Couldn’t create foo.txt");
298298
let buf = b"whatever";
299299
let result = f.write(buf);
300300
# result.unwrap(); // ignore the error

src/liballoc/arc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ impl<T: ?Sized> Clone for Weak<T> {
718718

719719
#[stable(feature = "downgraded_weak", since = "1.10.0")]
720720
impl<T> Default for Weak<T> {
721+
/// Constructs a new `Weak<T>` without an accompanying instance of T.
721722
fn default() -> Weak<T> {
722723
Weak::new()
723724
}
@@ -923,6 +924,7 @@ impl<T: ?Sized> fmt::Pointer for Arc<T> {
923924

924925
#[stable(feature = "rust1", since = "1.0.0")]
925926
impl<T: Default> Default for Arc<T> {
927+
/// Creates a new `Arc<T>`, with the `Default` value for T.
926928
fn default() -> Arc<T> {
927929
Arc::new(Default::default())
928930
}

src/liballoc/boxed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ impl<T: ?Sized> Box<T> {
290290

291291
#[stable(feature = "rust1", since = "1.0.0")]
292292
impl<T: Default> Default for Box<T> {
293+
/// Creates a `Box<T>`, with the `Default` value for T.
293294
fn default() -> Box<T> {
294295
box Default::default()
295296
}

src/liballoc/rc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
870870

871871
#[stable(feature = "downgraded_weak", since = "1.10.0")]
872872
impl<T> Default for Weak<T> {
873+
/// Creates a new `Weak<T>`.
873874
fn default() -> Weak<T> {
874875
Weak::new()
875876
}

src/libcollections/binary_heap.rs

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl<T: Clone> Clone for BinaryHeap<T> {
263263

264264
#[stable(feature = "rust1", since = "1.0.0")]
265265
impl<T: Ord> Default for BinaryHeap<T> {
266+
/// Creates an empty `BinaryHeap<T>`.
266267
#[inline]
267268
fn default() -> BinaryHeap<T> {
268269
BinaryHeap::new()

src/libcollections/borrow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl<'a, B: ?Sized> Default for Cow<'a, B>
249249
where B: ToOwned,
250250
<B as ToOwned>::Owned: Default
251251
{
252+
/// Creates an owned Cow<'a, B> with the default value for the contained owned value.
252253
fn default() -> Cow<'a, B> {
253254
Owned(<B as ToOwned>::Owned::default())
254255
}

src/libcollections/btree/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ impl<K: Hash, V: Hash> Hash for BTreeMap<K, V> {
16671667
}
16681668

16691669
impl<K: Ord, V> Default for BTreeMap<K, V> {
1670+
/// Creates an empty `BTreeMap<K, V>`.
16701671
fn default() -> BTreeMap<K, V> {
16711672
BTreeMap::new()
16721673
}

src/libcollections/btree/set.rs

+1
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BTreeSet<T> {
674674

675675
#[stable(feature = "rust1", since = "1.0.0")]
676676
impl<T: Ord> Default for BTreeSet<T> {
677+
/// Makes an empty `BTreeSet<T>` with a reasonable choice of B.
677678
fn default() -> BTreeSet<T> {
678679
BTreeSet::new()
679680
}

src/libcollections/linked_list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl<T> LinkedList<T> {
164164

165165
#[stable(feature = "rust1", since = "1.0.0")]
166166
impl<T> Default for LinkedList<T> {
167+
/// Creates an empty `LinkedList<T>`.
167168
#[inline]
168169
fn default() -> Self {
169170
Self::new()

src/libcollections/string.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,7 @@ impl_eq! { Cow<'a, str>, String }
15671567

15681568
#[stable(feature = "rust1", since = "1.0.0")]
15691569
impl Default for String {
1570+
/// Creates an empty `String`.
15701571
#[inline]
15711572
fn default() -> String {
15721573
String::new()

src/libcollections/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,7 @@ impl<T> Drop for Vec<T> {
16521652

16531653
#[stable(feature = "rust1", since = "1.0.0")]
16541654
impl<T> Default for Vec<T> {
1655+
/// Creates an empty `Vec<T>`.
16551656
fn default() -> Vec<T> {
16561657
Vec::new()
16571658
}

src/libcollections/vec_deque.rs

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl<T> Drop for VecDeque<T> {
8484

8585
#[stable(feature = "rust1", since = "1.0.0")]
8686
impl<T> Default for VecDeque<T> {
87+
/// Creates an empty `VecDeque<T>`.
8788
#[inline]
8889
fn default() -> VecDeque<T> {
8990
VecDeque::new()

src/libcore/cell.rs

+3
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ impl<T:Copy> Clone for Cell<T> {
317317

318318
#[stable(feature = "rust1", since = "1.0.0")]
319319
impl<T:Default + Copy> Default for Cell<T> {
320+
/// Creates a `Cell<T>`, with the `Default` value for T.
320321
#[inline]
321322
fn default() -> Cell<T> {
322323
Cell::new(Default::default())
@@ -758,6 +759,7 @@ impl<T: Clone> Clone for RefCell<T> {
758759

759760
#[stable(feature = "rust1", since = "1.0.0")]
760761
impl<T:Default> Default for RefCell<T> {
762+
/// Creates a `RefCell<T>`, with the `Default` value for T.
761763
#[inline]
762764
fn default() -> RefCell<T> {
763765
RefCell::new(Default::default())
@@ -1139,6 +1141,7 @@ impl<T: ?Sized> UnsafeCell<T> {
11391141

11401142
#[stable(feature = "unsafe_cell_default", since = "1.9.0")]
11411143
impl<T: Default> Default for UnsafeCell<T> {
1144+
/// Creates an `UnsafeCell`, with the `Default` value for T.
11421145
fn default() -> UnsafeCell<T> {
11431146
UnsafeCell::new(Default::default())
11441147
}

src/libcore/clone.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
//! assign them or pass them as arguments, the receiver will get a copy,
1515
//! leaving the original value in place. These types do not require
1616
//! allocation to copy and do not have finalizers (i.e. they do not
17-
//! contain owned boxes or implement `Drop`), so the compiler considers
17+
//! contain owned boxes or implement [`Drop`]), so the compiler considers
1818
//! them cheap and safe to copy. For other types copies must be made
19-
//! explicitly, by convention implementing the `Clone` trait and calling
20-
//! the `clone` method.
19+
//! explicitly, by convention implementing the [`Clone`] trait and calling
20+
//! the [`clone`][clone] method.
21+
//!
22+
//! [`Clone`]: trait.Clone.html
23+
//! [clone]: trait.Clone.html#tymethod.clone
24+
//! [`Drop`]: ../../std/ops/trait.Drop.html
2125
//!
2226
//! Basic usage example:
2327
//!
@@ -46,22 +50,22 @@
4650

4751
/// A common trait for the ability to explicitly duplicate an object.
4852
///
49-
/// Differs from `Copy` in that `Copy` is implicit and extremely inexpensive, while
53+
/// Differs from [`Copy`] in that [`Copy`] is implicit and extremely inexpensive, while
5054
/// `Clone` is always explicit and may or may not be expensive. In order to enforce
51-
/// these characteristics, Rust does not allow you to reimplement `Copy`, but you
55+
/// these characteristics, Rust does not allow you to reimplement [`Copy`], but you
5256
/// may reimplement `Clone` and run arbitrary code.
5357
///
54-
/// Since `Clone` is more general than `Copy`, you can automatically make anything
55-
/// `Copy` be `Clone` as well.
58+
/// Since `Clone` is more general than [`Copy`], you can automatically make anything
59+
/// [`Copy`] be `Clone` as well.
5660
///
5761
/// ## Derivable
5862
///
5963
/// This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d
60-
/// implementation of `clone()` calls `clone()` on each field.
64+
/// implementation of [`clone()`] calls [`clone()`] on each field.
6165
///
6266
/// ## How can I implement `Clone`?
6367
///
64-
/// Types that are `Copy` should have a trivial implementation of `Clone`. More formally:
68+
/// Types that are [`Copy`] should have a trivial implementation of `Clone`. More formally:
6569
/// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`.
6670
/// Manual implementations should be careful to uphold this invariant; however, unsafe code
6771
/// must not rely on it to ensure memory safety.
@@ -70,6 +74,9 @@
7074
/// library only implements `Clone` up until arrays of size 32. In this case, the implementation of
7175
/// `Clone` cannot be `derive`d, but can be implemented as:
7276
///
77+
/// [`Copy`]: ../../std/marker/trait.Copy.html
78+
/// [`clone()`]: trait.Clone.html#tymethod.clone
79+
///
7380
/// ```
7481
/// #[derive(Copy)]
7582
/// struct Stats {

src/libcore/hash/sip.rs

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ impl<S: Sip> Clone for Hasher<S> {
333333
}
334334

335335
impl<S: Sip> Default for Hasher<S> {
336+
/// Creates a `Hasher<S>` with the two initial keys set to 0.
336337
#[inline]
337338
fn default() -> Hasher<S> {
338339
Hasher::new_with_keys(0, 0)

src/libcore/marker.rs

+35-16
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub trait Unsize<T: ?Sized> {
126126
/// }
127127
/// ```
128128
///
129-
/// The `PointList` `struct` cannot implement `Copy`, because `Vec<T>` is not `Copy`. If we
129+
/// The `PointList` `struct` cannot implement `Copy`, because [`Vec<T>`] is not `Copy`. If we
130130
/// attempt to derive a `Copy` implementation, we'll get an error:
131131
///
132132
/// ```text
@@ -136,10 +136,10 @@ pub trait Unsize<T: ?Sized> {
136136
/// ## When can my type _not_ be `Copy`?
137137
///
138138
/// Some types can't be copied safely. For example, copying `&mut T` would create an aliased
139-
/// mutable reference, and copying `String` would result in two attempts to free the same buffer.
139+
/// mutable reference, and copying [`String`] would result in two attempts to free the same buffer.
140140
///
141-
/// Generalizing the latter case, any type implementing `Drop` can't be `Copy`, because it's
142-
/// managing some resource besides its own `size_of::<T>()` bytes.
141+
/// Generalizing the latter case, any type implementing [`Drop`] can't be `Copy`, because it's
142+
/// managing some resource besides its own [`size_of::<T>()`] bytes.
143143
///
144144
/// ## What if I derive `Copy` on a type that can't?
145145
///
@@ -156,8 +156,7 @@ pub trait Unsize<T: ?Sized> {
156156
///
157157
/// ## Derivable
158158
///
159-
/// This trait can be used with `#[derive]` if all of its components implement `Copy` and the type
160-
/// implements `Clone`. The implementation will copy the bytes of each field using `memcpy`.
159+
/// This trait can be used with `#[derive]` if all of its components implement `Copy` and the type.
161160
///
162161
/// ## How can I implement `Copy`?
163162
///
@@ -178,6 +177,11 @@ pub trait Unsize<T: ?Sized> {
178177
///
179178
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
180179
/// bound on type parameters, which isn't always desired.
180+
///
181+
/// [`Vec<T>`]: ../../std/vec/struct.Vec.html
182+
/// [`String`]: ../../std/string/struct.String.html
183+
/// [`Drop`]: ../../std/ops/trait.Drop.html
184+
/// [`size_of::<T>()`]: ../../std/mem/fn.size_of.html
181185
#[stable(feature = "rust1", since = "1.0.0")]
182186
#[lang = "copy"]
183187
pub trait Copy : Clone {
@@ -190,11 +194,11 @@ pub trait Copy : Clone {
190194
/// thread-safe. In other words, there is no possibility of data races
191195
/// when passing `&T` references between threads.
192196
///
193-
/// As one would expect, primitive types like `u8` and `f64` are all
197+
/// As one would expect, primitive types like [`u8`] and [`f64`] are all
194198
/// `Sync`, and so are simple aggregate types containing them (like
195199
/// tuples, structs and enums). More instances of basic `Sync` types
196200
/// include "immutable" types like `&T` and those with simple
197-
/// inherited mutability, such as `Box<T>`, `Vec<T>` and most other
201+
/// inherited mutability, such as [`Box<T>`], [`Vec<T>`] and most other
198202
/// collection types. (Generic parameters need to be `Sync` for their
199203
/// container to be `Sync`.)
200204
///
@@ -206,27 +210,42 @@ pub trait Copy : Clone {
206210
/// race.
207211
///
208212
/// Types that are not `Sync` are those that have "interior
209-
/// mutability" in a non-thread-safe way, such as `Cell` and `RefCell`
210-
/// in `std::cell`. These types allow for mutation of their contents
213+
/// mutability" in a non-thread-safe way, such as [`Cell`] and [`RefCell`]
214+
/// in [`std::cell`]. These types allow for mutation of their contents
211215
/// even when in an immutable, aliasable slot, e.g. the contents of
212-
/// `&Cell<T>` can be `.set`, and do not ensure data races are
216+
/// [`&Cell<T>`][`Cell`] can be [`.set`], and do not ensure data races are
213217
/// impossible, hence they cannot be `Sync`. A higher level example
214218
/// of a non-`Sync` type is the reference counted pointer
215-
/// `std::rc::Rc`, because any reference `&Rc<T>` can clone a new
219+
/// [`std::rc::Rc`][`Rc`], because any reference [`&Rc<T>`][`Rc`] can clone a new
216220
/// reference, which modifies the reference counts in a non-atomic
217221
/// way.
218222
///
219223
/// For cases when one does need thread-safe interior mutability,
220-
/// types like the atomics in `std::sync` and `Mutex` & `RWLock` in
221-
/// the `sync` crate do ensure that any mutation cannot cause data
224+
/// types like the atomics in [`std::sync`][`sync`] and [`Mutex`] / [`RwLock`] in
225+
/// the [`sync`] crate do ensure that any mutation cannot cause data
222226
/// races. Hence these types are `Sync`.
223227
///
224-
/// Any types with interior mutability must also use the `std::cell::UnsafeCell`
228+
/// Any types with interior mutability must also use the [`std::cell::UnsafeCell`]
225229
/// wrapper around the value(s) which can be mutated when behind a `&`
226230
/// reference; not doing this is undefined behavior (for example,
227-
/// `transmute`-ing from `&T` to `&mut T` is invalid).
231+
/// [`transmute`]-ing from `&T` to `&mut T` is invalid).
228232
///
229233
/// This trait is automatically derived when the compiler determines it's appropriate.
234+
///
235+
/// [`u8`]: ../../std/primitive.u8.html
236+
/// [`f64`]: ../../std/primitive.f64.html
237+
/// [`Vec<T>`]: ../../std/vec/struct.Vec.html
238+
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
239+
/// [`Cell`]: ../../std/cell/struct.Cell.html
240+
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
241+
/// [`std::cell`]: ../../std/cell/index.html
242+
/// [`.set`]: ../../std/cell/struct.Cell.html#method.set
243+
/// [`Rc`]: ../../std/rc/struct.Rc.html
244+
/// [`sync`]: ../../std/sync/index.html
245+
/// [`Mutex`]: ../../std/sync/struct.Mutex.html
246+
/// [`RwLock`]: ../../std/sync/struct.RwLock.html
247+
/// [`std::cell::UnsafeCell`]: ../../std/cell/struct.UnsafeCell.html
248+
/// [`transmute`]: ../../std/mem/fn.transmute.html
230249
#[stable(feature = "rust1", since = "1.0.0")]
231250
#[lang = "sync"]
232251
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]

0 commit comments

Comments
 (0)