Skip to content

Commit

Permalink
Add explanations about what derived trait implementations do
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed May 23, 2016
1 parent 4c6b6c2 commit 1e493fd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/libcore/clone.rs
Expand Up @@ -48,7 +48,8 @@ use marker::Sized;

/// A common trait for cloning an object.
///
/// This trait can be used with `#[derive]`.
/// This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d
/// implementation of `clone()` calls `clone()` on each field.
///
/// Types that are `Copy` should have a trivial implementation of `Clone`. More formally:
/// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`.
Expand Down
9 changes: 7 additions & 2 deletions src/libcore/cmp.rs
Expand Up @@ -58,7 +58,10 @@ use option::Option::{self, Some};
/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
/// only if `a != b`.
///
/// This trait can be used with `#[derive]`.
/// This trait can be used with `#[derive]`. When `derive`d on structs, two
/// instances are equal if all fields are equal, and non equal if any fields
/// are not equal. When `derive`d on enums, each variant is equal to itself
/// and not equal to the other variants.
///
/// # Examples
///
Expand Down Expand Up @@ -96,7 +99,9 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
/// This property cannot be checked by the compiler, and therefore `Eq` implies
/// `PartialEq`, and has no extra methods.
///
/// This trait can be used with `#[derive]`.
/// This trait can be used with `#[derive]`. When `derive`d, because `Eq` has
/// no extra methods, it is only informing the compiler that this is an
/// equivalence relation rather than a partial equivalence relation.
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Eq: PartialEq<Self> {
// FIXME #13101: this method is used solely by #[deriving] to
Expand Down
6 changes: 5 additions & 1 deletion src/libcore/fmt/mod.rs
Expand Up @@ -318,7 +318,11 @@ impl<'a> Display for Arguments<'a> {
///
/// [module]: ../../std/fmt/index.html
///
/// This trait can be used with `#[derive]`.
/// This trait can be used with `#[derive]` if all fields implement `Debug`. When
/// `derive`d for structs, it will use the name of the `struct`, then `{`, then a
/// comma-separated list of each field's name and `Debug` value, then `}`. For
/// `enum`s, it will use the name of the variant and, if applicable, `(`, then the
/// `Debug` values of the fields, then `)`.
///
/// # Examples
///
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/hash/mod.rs
Expand Up @@ -97,7 +97,9 @@ mod sip;
/// In other words, if two keys are equal, their hashes should also be equal.
/// `HashMap` and `HashSet` both rely on this behavior.
///
/// This trait can be used with `#[derive]`.
/// This trait can be used with `#[derive]` if all fields implement `Hash`.
/// When `derive`d, the resulting hash will be the combination of the values
/// from calling `.hash()` on each field.
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Hash {
/// Feeds this value into the state given, updating the hasher as necessary.
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/marker.rs
Expand Up @@ -173,7 +173,8 @@ pub trait Unsize<T: ?Sized> {
///
/// # Derivable
///
/// This trait can be used with `#[derive]`.
/// This trait can be used with `#[derive]` if all of its components implement `Copy` and the type
/// implements `Clone`. The implementation will copy the bytes of each field using `memcpy`.
#[stable(feature = "rust1", since = "1.0.0")]
#[lang = "copy"]
pub trait Copy : Clone {
Expand Down

0 comments on commit 1e493fd

Please sign in to comment.