Skip to content

Commit fc1c118

Browse files
committed
Auto merge of #31510 - dikaiosune:master, r=bluss
Since a lexicographic ordering of a struct could vary based on which struct members are compared first, I ended up doing some testing to ensure that the behavior when deriving these traits was what I expected (ordered based on the top to bottom order of declaration of the members). I wanted to add this little bit of documentation to potentially save someone else the same effort. That is, assuming that my testing correctly reflects the intended behavior of the compiler. r? @steveklabnik
2 parents 6630a08 + e22770b commit fc1c118

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libcore/cmp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ impl Ordering {
165165
/// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and
166166
/// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
167167
///
168-
/// When this trait is `derive`d, it produces a lexicographic ordering.
169-
///
170-
/// This trait can be used with `#[derive]`.
168+
/// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic
169+
/// ordering based on the top-to-bottom declaration order of the struct's members.
171170
#[stable(feature = "rust1", since = "1.0.0")]
172171
pub trait Ord: Eq + PartialOrd<Self> {
173172
/// This method returns an `Ordering` between `self` and `other`.
@@ -225,7 +224,8 @@ impl PartialOrd for Ordering {
225224
/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
226225
/// false` (cf. IEEE 754-2008 section 5.11).
227226
///
228-
/// This trait can be used with `#[derive]`.
227+
/// This trait can be used with `#[derive]`. When `derive`d, it will produce an ordering
228+
/// based on the top-to-bottom declaration order of the struct's members.
229229
#[lang = "ord"]
230230
#[stable(feature = "rust1", since = "1.0.0")]
231231
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {

0 commit comments

Comments
 (0)