-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustdoc: Add PartialOrd trait to doc comment explanation #104068
Conversation
r? @scottmcm (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rustbot author
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those | ||
/// of another. | ||
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`], which | ||
/// implements the `PartialOrd` trait, with those of another. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I like the idea that improving the comment here, but I think this isn't quite the right phrasing, since it could be interpreted as the iterator implementing the PartialOrd
trait, especially with the word "implements".
Maybe something like "compares the PartialOrd
elements of this"?
Also, while you're here, it would be great to have some prose about what happens for incomparable items like NANs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scottmcm, thanks. I agree that adding an explanation about PartialOrd
elements is correct. I also added some prose about using partial_cmp
with things like NANs
.
ca5cdcf
to
06077d0
Compare
This comment has been minimized.
This comment has been minimized.
06077d0
to
6177eb9
Compare
If you've made changes to resolve any issues brought up during review, then mark the PR as waiting on review with |
@rustbot ready |
/// of another. | ||
/// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of | ||
/// this [`Iterator`] with those of another. A [`Option`] type is returned and will either be | ||
/// [`Some`] if the types have a total order, or else [`None`]. For example, for floating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I've got more phrasing nitpicks here.
let it1 = std::iter::repeat(1.0);
let it2 = std::iter::repeat(2.0);
dbg!(it1.partial_cmp(it2));
returns Some(Less)
here, but that doesn't mean that the types have a total order, just that the values observed were ordered.
Maybe there's a way to phrase it in terms of if PartialOrd::partial_cmp
every returns None
from any of the comparisons done, then this will also return None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there's a way to phrase it in terms of if PartialOrd::partial_cmp every returns None from any of the comparisons done, then this will also return None?
Wouldn't it be more descriptive to explain that as soon as an orderings can be determined the evaluation stops (similar to how short-circuit evaluation works)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that sounds good too!
/// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of | ||
/// this [`Iterator`] with those of another. A [`Option`] type is returned and will either be | ||
/// [`Some`] if the types have a total order, or else [`None`]. For example, for floating | ||
/// point numbers, NaN does not have a total order and will result in the [`None`] variant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the prose says "for example", then consider putting it down in the # Examples
section with a runnable example.
Perhaps take this part
/// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
///
/// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
/// ```
and put your text in there?
/// 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);
/// ```
You could also add some more examples about it here, like comparing [1.0, NAN]
with [2.0, NAN]
, where you'll get a result despite the NANs since the prefix is enough to decide the lexicographical order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for taking a while to get back to this. I had a few more thoughts about it.
@rustbot author
6177eb9
to
248c340
Compare
@scottmcm no problem. Thanks for the feedback. |
@rustbot ready |
248c340
to
ced9629
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I'll wait for CI to confirm, though.
@bors r+ rollup=always |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#104068 (rustdoc: Add PartialOrd trait to doc comment explanation) - rust-lang#107489 (Implement partial support for non-lifetime binders) - rust-lang#107905 (Pass arguments to `x` subcommands with `--`) - rust-lang#108009 (Move some tests) - rust-lang#108086 (wasm: Register the `relaxed-simd` target feature) - rust-lang#108104 (don't into self) - rust-lang#108133 (Small cleanups around `EarlyBinder`) - rust-lang#108136 (Do not ICE on unmet trait alias impl bounds) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The doc comments for partial_cmp is the exact same as the doc comment for cmp. This PR adds to the description
partial_cmp
to disambiguate the description fromcmp.