@@ -126,7 +126,7 @@ pub trait Unsize<T: ?Sized> {
126
126
/// }
127
127
/// ```
128
128
///
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
130
130
/// attempt to derive a `Copy` implementation, we'll get an error:
131
131
///
132
132
/// ```text
@@ -136,10 +136,10 @@ pub trait Unsize<T: ?Sized> {
136
136
/// ## When can my type _not_ be `Copy`?
137
137
///
138
138
/// 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.
140
140
///
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.
143
143
///
144
144
/// ## What if I derive `Copy` on a type that can't?
145
145
///
@@ -156,8 +156,7 @@ pub trait Unsize<T: ?Sized> {
156
156
///
157
157
/// ## Derivable
158
158
///
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.
161
160
///
162
161
/// ## How can I implement `Copy`?
163
162
///
@@ -178,6 +177,11 @@ pub trait Unsize<T: ?Sized> {
178
177
///
179
178
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
180
179
/// 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
181
185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
182
186
#[ lang = "copy" ]
183
187
pub trait Copy : Clone {
@@ -190,11 +194,11 @@ pub trait Copy : Clone {
190
194
/// thread-safe. In other words, there is no possibility of data races
191
195
/// when passing `&T` references between threads.
192
196
///
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
194
198
/// `Sync`, and so are simple aggregate types containing them (like
195
199
/// tuples, structs and enums). More instances of basic `Sync` types
196
200
/// 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
198
202
/// collection types. (Generic parameters need to be `Sync` for their
199
203
/// container to be `Sync`.)
200
204
///
@@ -206,27 +210,42 @@ pub trait Copy : Clone {
206
210
/// race.
207
211
///
208
212
/// 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
211
215
/// 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
213
217
/// impossible, hence they cannot be `Sync`. A higher level example
214
218
/// 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
216
220
/// reference, which modifies the reference counts in a non-atomic
217
221
/// way.
218
222
///
219
223
/// 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
222
226
/// races. Hence these types are `Sync`.
223
227
///
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`]
225
229
/// wrapper around the value(s) which can be mutated when behind a `&`
226
230
/// 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).
228
232
///
229
233
/// 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
230
249
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
231
250
#[ lang = "sync" ]
232
251
#[ rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely" ]
0 commit comments