Skip to content

Commit 6379c72

Browse files
authored
Rollup merge of #104068 - yancyribbens:partial-cmp-doc-update, r=scottmcm
rustdoc: Add PartialOrd trait to doc comment explanation The doc comments for [partial_cmp](https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/iterator.rs#L3478) is the exact same as the doc comment for [cmp](https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/iterator.rs#L3413). This PR adds to the description `partial_cmp` to disambiguate the description from `cmp.`
2 parents 9a7cc6c + ced9629 commit 6379c72

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

library/core/src/iter/traits/iterator.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -3502,8 +3502,10 @@ pub trait Iterator {
35023502
}
35033503
}
35043504

3505-
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
3506-
/// of another.
3505+
/// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of
3506+
/// this [`Iterator`] with those of another. The comparison works like short-circuit
3507+
/// evaluation, returning a result without comparing the remaining elements.
3508+
/// As soon as an order can be determined, the evaluation stops and a result is returned.
35073509
///
35083510
/// # Examples
35093511
///
@@ -3513,9 +3515,25 @@ pub trait Iterator {
35133515
/// assert_eq!([1.].iter().partial_cmp([1.].iter()), Some(Ordering::Equal));
35143516
/// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less));
35153517
/// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
3518+
/// ```
35163519
///
3520+
/// For floating-point numbers, NaN does not have a total order and will result
3521+
/// in `None` when compared:
3522+
///
3523+
/// ```
35173524
/// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
35183525
/// ```
3526+
///
3527+
/// The results are determined by the order of evaluation.
3528+
///
3529+
/// ```
3530+
/// use std::cmp::Ordering;
3531+
///
3532+
/// assert_eq!([1.0, f64::NAN].iter().partial_cmp([2.0, f64::NAN].iter()), Some(Ordering::Less));
3533+
/// assert_eq!([2.0, f64::NAN].iter().partial_cmp([1.0, f64::NAN].iter()), Some(Ordering::Greater));
3534+
/// assert_eq!([f64::NAN, 1.0].iter().partial_cmp([f64::NAN, 2.0].iter()), None);
3535+
/// ```
3536+
///
35193537
#[stable(feature = "iter_order", since = "1.5.0")]
35203538
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
35213539
where

0 commit comments

Comments
 (0)