@@ -278,7 +278,7 @@ pub macro PartialEq($item:item) {
278
278
/// The primary difference to [`PartialEq`] is the additional requirement for reflexivity. A type
279
279
/// that implements [`PartialEq`] guarantees that for all `a`, `b` and `c`:
280
280
///
281
- /// - symmetric: `a == b` implies `b == a`
281
+ /// - symmetric: `a == b` implies `b == a` and `a != b` implies `!(a == b)`
282
282
/// - transitive: `a == b` and `b == c` implies `a == c`
283
283
///
284
284
/// `Eq`, which builds on top of [`PartialEq`] also implies:
@@ -332,11 +332,9 @@ pub macro PartialEq($item:item) {
332
332
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
333
333
#[ rustc_diagnostic_item = "Eq" ]
334
334
pub 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.
340
338
//
341
339
// This should never be implemented by hand.
342
340
#[ doc( hidden) ]
@@ -789,11 +787,13 @@ impl<T: Clone> Clone for Reverse<T> {
789
787
/// fashion `Ord` builds on top of [`PartialOrd`] and adds further properties, such as totality,
790
788
/// which means all values must be comparable.
791
789
///
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`.
797
797
///
798
798
/// Here's an example where you want to define the `Character` comparison by `health` and
799
799
/// `experience` only, disregarding the field `mana`:
@@ -888,7 +888,7 @@ impl<T: Clone> Clone for Reverse<T> {
888
888
/// ```
889
889
/// use std::cmp::Ordering;
890
890
///
891
- /// #[derive(Eq, Debug)]
891
+ /// #[derive(Debug)]
892
892
/// struct Character {
893
893
/// health: u32,
894
894
/// experience: u32,
@@ -918,6 +918,8 @@ impl<T: Clone> Clone for Reverse<T> {
918
918
/// }
919
919
/// }
920
920
///
921
+ /// impl Eq for Character {}
922
+ ///
921
923
/// let a = Character {
922
924
/// health: 3,
923
925
/// experience: 5,
@@ -1192,7 +1194,6 @@ pub macro Ord($item:item) {
1192
1194
/// ```
1193
1195
/// use std::cmp::Ordering;
1194
1196
///
1195
- /// #[derive(Eq)]
1196
1197
/// struct Person {
1197
1198
/// id: u32,
1198
1199
/// name: String,
@@ -1216,6 +1217,8 @@ pub macro Ord($item:item) {
1216
1217
/// self.height == other.height
1217
1218
/// }
1218
1219
/// }
1220
+ ///
1221
+ /// impl Eq for Person {}
1219
1222
/// ```
1220
1223
///
1221
1224
/// You may also find it useful to use [`partial_cmp`] on your type's fields. Here is an example of
0 commit comments