Skip to content

No definition of lexicographic order in docs for Iterator::cmp* #72255

Description

@brmmm3

It seems that the comparison functions are not correctly implemented.

I tried this code:

use std::cmp::Ordering;

assert_eq!([1].iter().cmp([1, 2].iter()), Ordering::Less);
assert_eq!([1, 2].iter().cmp([1].iter()), Ordering::Greater);

I expected to see this happen:
The code above should panic. The reason is: 1 is NOT less than 1 and 1 is NOT greater than 1.
What I'm missing in Ordering are LessOrEqual and GreaterOrEqual. If these 2 objects would exist I could write:

use std::cmp::Ordering;

assert_eq!([1].iter().cmp([1, 2].iter()), Ordering::LessOrEqual);
assert_eq!([1, 2].iter().cmp([1].iter()), Ordering::GreaterOrEqual);

which would correct not panic.

Meta

I've tried this in Rust Playground with stable and nightly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions