about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-17 00:19:33 +0100
committerGitHub <noreply@github.com>2023-02-17 00:19:33 +0100
commit6379c727ace0cfc1eaab093f297b97e1ffb8bb30 (patch)
treec677bcb0a082066b947f537c2ad7315be4c6ce51
parent9a7cc6c32f1a690f86827e4724bcda85e506ef35 (diff)
parentced962975b5d42607ec50425e6b2d8d504784248 (diff)
downloadrust-6379c727ace0cfc1eaab093f297b97e1ffb8bb30.tar.gz
rust-6379c727ace0cfc1eaab093f297b97e1ffb8bb30.zip
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.`
-rw-r--r--library/core/src/iter/traits/iterator.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs
index 5a0b8594104..9e3e13e7004 100644
--- a/library/core/src/iter/traits/iterator.rs
+++ b/library/core/src/iter/traits/iterator.rs
@@ -3502,8 +3502,10 @@ pub trait Iterator {
         }
     }
 
-    /// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
-    /// of another.
+    /// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of
+    /// this [`Iterator`] with those of another. The comparison works like short-circuit
+    /// evaluation, returning a result without comparing the remaining elements.
+    /// As soon as an order can be determined, the evaluation stops and a result is returned.
     ///
     /// # Examples
     ///
@@ -3513,9 +3515,25 @@ pub trait Iterator {
     /// assert_eq!([1.].iter().partial_cmp([1.].iter()), Some(Ordering::Equal));
     /// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less));
     /// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
+    /// ```
     ///
+    /// For floating-point numbers, NaN does not have a total order and will result
+    /// in `None` when compared:
+    ///
+    /// ```
     /// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
     /// ```
+    ///
+    /// The results are determined by the order of evaluation.
+    ///
+    /// ```
+    /// use std::cmp::Ordering;
+    ///
+    /// assert_eq!([1.0, f64::NAN].iter().partial_cmp([2.0, f64::NAN].iter()), Some(Ordering::Less));
+    /// assert_eq!([2.0, f64::NAN].iter().partial_cmp([1.0, f64::NAN].iter()), Some(Ordering::Greater));
+    /// assert_eq!([f64::NAN, 1.0].iter().partial_cmp([f64::NAN, 2.0].iter()), None);
+    /// ```
+    ///
     #[stable(feature = "iter_order", since = "1.5.0")]
     fn partial_cmp<I>(self, other: I) -> Option<Ordering>
     where