Apply round 1 of review comments · qinheping/verify-rust-std@df28bde (original) (raw)

`@@ -281,12 +281,11 @@ pub macro PartialEq($item:item) {

`

281

281

`` /// - symmetric: a == b implies b == a

``

282

282

`` /// - transitive: a == b and b == c implies a == c

``

283

283

`///

`

284

``

`` -

/// Eq which builds on top of [PartialEq] also implies:

``

``

284

`` +

/// Eq, which builds on top of [PartialEq] also implies:

``

285

285

`///

`

286

286

`` /// - reflexive: a == a

``

287

287

`///

`

288

``

`` -

/// This property cannot be checked by the compiler, and therefore Eq is a marker trait without

``

289

``

`-

/// methods.

`

``

288

`` +

/// This property cannot be checked by the compiler, and therefore Eq is a trait without methods.

``

290

289

`///

`

291

290

`/// Violating this property is a logic error. The behavior resulting from a logic error is not

`

292

291

`/// specified, but users of the trait must ensure that such logic errors do not result in

`

`@@ -778,18 +777,17 @@ impl<T: Clone> Clone for Reverse {

`

778

777

`///

`

779

778

`` /// ## How can I implement Ord?

``

780

779

`///

`

781

``

`` -

/// Ord requires that the type also be [PartialOrd] and [Eq] which itself requires

``

782

``

`` -

/// [PartialEq].

``

``

780

`` +

/// Ord requires that the type also be [PartialOrd], [PartialEq] and [Eq].

``

783

781

`///

`

784

``

`` -

/// Non derived implementations of Ord require that the [cmp] function is implemented

``

785

``

`` -

/// manually. It's a logic error to have [PartialOrd] and Ord disagree, so it's best practice to

``

786

``

`` -

/// have the logic in Ord and implement [PartialOrd] as Some(self.cmp(other)).

``

``

782

`` +

/// If you manually implement Ord, you should also implement [PartialOrd]. It is a logic error

``

``

783

`` +

/// to have [PartialOrd] and Ord disagree, so it is best to have the logic in Ord and

``

``

784

`` +

/// implement [PartialOrd] as Some(self.cmp(other)).

``

787

785

`///

`

788

786

`` /// Conceptually [PartialOrd] and Ord form a similar relationship to [PartialEq] and [Eq].

``

789

``

`` -

/// [PartialEq] implements and implies an equality relationship between types, and [Eq] implies

``

790

``

`` -

/// an additional property on top of the properties implied by [PartialOrd], namely reflexivity.

``

791

``

`` -

/// In a similar fashion Ord builds on top of [PartialOrd] and implies further properties, such

``

792

``

`-

/// as totality, which means all values must be comparable.

`

``

787

`` +

/// [PartialEq] defines an equality relationship between types, and [Eq] defines an additional

``

``

788

`` +

/// property on top of the properties implied by [PartialEq], namely reflexivity. In a similar

``

``

789

`` +

/// fashion Ord builds on top of [PartialOrd] and adds further properties, such as totality,

``

``

790

`+

/// which means all values must be comparable.

`

793

791

`///

`

794

792

`` /// Because of different signatures, Ord cannot be a simple marker trait like Eq. So it can't be

``

795

793

`` /// derived automatically when PartialOrd is implemented. The recommended best practice for a

``

`@@ -811,9 +809,9 @@ impl<T: Clone> Clone for Reverse {

`

811

809

`///

`

812

810

`/// impl Ord for Character {

`

813

811

`/// fn cmp(&self, other: &Self) -> std::cmp::Ordering {

`

814

``

`-

/// self.health

`

815

``

`-

/// .cmp(&other.health)

`

816

``

`-

/// .then(self.experience.cmp(&other.experience))

`

``

812

`+

/// self.experience

`

``

813

`+

/// .cmp(&other.experience)

`

``

814

`+

/// .then(self.health.cmp(&other.health))

`

817

815

`/// }

`

818

816

`/// }

`

819

817

`///

`

`@@ -1075,7 +1073,8 @@ pub macro Ord($item:item) {

`

1075

1073

`` /// 1. a == b if and only if partial_cmp(a, b) == Some(Equal).

``

1076

1074

`` /// 2. a < b if and only if partial_cmp(a, b) == Some(Less)

``

1077

1075

`` /// 3. a > b if and only if partial_cmp(a, b) == Some(Greater)

``

1078

``

`` -

/// 4. a <= b if and only if a < b || a == b 5. a >= b if and only if a > b || a == b

``

``

1076

`` +

/// 4. a <= b if and only if a < b || a == b

``

``

1077

`` +

/// 5. a >= b if and only if a > b || a == b

``

1079

1078

`` /// 6. a != b if and only if !(a == b).

``

1080

1079

`///

`

1081

1080

`/// Conditions 2–5 above are ensured by the default implementation. Condition 6 is already ensured

`