@@ -278,7 +278,7 @@ pub macro PartialEq($item:item) {
278278/// The primary difference to [`PartialEq`] is the additional requirement for reflexivity. A type
279279/// that implements [`PartialEq`] guarantees that for all `a`, `b` and `c`:
280280///
281- /// - symmetric: `a == b` implies `b == a`
281+ /// - symmetric: `a == b` implies `b == a` and `a != b` implies `!(a == b)`
282282/// - transitive: `a == b` and `b == c` implies `a == c`
283283///
284284/// `Eq`, which builds on top of [`PartialEq`] also implies:
@@ -332,11 +332,9 @@ pub macro PartialEq($item:item) {
332332#[ stable( feature = "rust1" , since = "1.0.0" ) ]
333333#[ rustc_diagnostic_item = "Eq" ]
334334pub trait Eq : PartialEq < Self > {
335- // this method is used solely by #[derive(Eq)] to assert
336- // that every component of a type implements `Eq`
337- // itself. The current deriving infrastructure means doing this
338- // assertion without using a method on this trait is nearly
339- // impossible.
335+ // this method is used solely by `impl Eq or #[derive(Eq)]` to assert that every component of a
336+ // type implements `Eq` itself. The current deriving infrastructure means doing this assertion
337+ // without using a method on this trait is nearly impossible.
340338 //
341339 // This should never be implemented by hand.
342340 #[ doc( hidden) ]
@@ -789,11 +787,13 @@ impl<T: Clone> Clone for Reverse<T> {
789787/// fashion `Ord` builds on top of [`PartialOrd`] and adds further properties, such as totality,
790788/// which means all values must be comparable.
791789///
792- /// Because of different signatures, `Ord` cannot be a simple marker trait like `Eq`. So it can't be
793- /// `derive`d automatically when `PartialOrd` is implemented. The recommended best practice for a
794- /// type that manually implements `Ord` is to implement the equality comparison logic in `PartialEq`
795- /// and implement the ordering comparison logic in `Ord`. From there one should implement
796- /// `PartialOrd` as `Some(self.cmp(other))`.
790+ /// `Ord` requires that the type also be PartialOrd, PartialEq, and Eq.
791+ ///
792+ /// Because `Ord` implies a stronger ordering relationship than [`PartialOrd`], and both `Ord` and
793+ /// [`PartialOrd`] must agree, you must choose how to implement `Ord` **first**. You can choose to
794+ /// derive it, or implement it manually. If you derive it, you should derive all four traits. If you
795+ /// implement it manually, you should manually implement all four traits, based on the
796+ /// implementation of `Ord`.
797797///
798798/// Here's an example where you want to define the `Character` comparison by `health` and
799799/// `experience` only, disregarding the field `mana`:
@@ -888,7 +888,7 @@ impl<T: Clone> Clone for Reverse<T> {
888888/// ```
889889/// use std::cmp::Ordering;
890890///
891- /// #[derive(Eq, Debug)]
891+ /// #[derive(Debug)]
892892/// struct Character {
893893/// health: u32,
894894/// experience: u32,
@@ -918,6 +918,8 @@ impl<T: Clone> Clone for Reverse<T> {
918918/// }
919919/// }
920920///
921+ /// impl Eq for Character {}
922+ ///
921923/// let a = Character {
922924/// health: 3,
923925/// experience: 5,
@@ -1192,7 +1194,6 @@ pub macro Ord($item:item) {
11921194/// ```
11931195/// use std::cmp::Ordering;
11941196///
1195- /// #[derive(Eq)]
11961197/// struct Person {
11971198/// id: u32,
11981199/// name: String,
@@ -1216,6 +1217,8 @@ pub macro Ord($item:item) {
12161217/// self.height == other.height
12171218/// }
12181219/// }
1220+ ///
1221+ /// impl Eq for Person {}
12191222/// ```
12201223///
12211224/// You may also find it useful to use [`partial_cmp`] on your type's fields. Here is an example of
0 commit comments