Skip to content

Make clarifications for binary_search API #124882

Open
@non-descriptive

Description

@non-descriptive

Location

https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search

Summary

Documentation states, that

If the slice is not sorted, the returned result is unspecified and meaningless.

but if we try to use binary search on something like [5,4,3,2,1].binary_search(&5) it will end up with error, though the slice is sorted in descending order.
This either requires to fix docs to something like

If the slice is not sorted in ascending order, the returned result is unspecified and meaningless.

or fix actual binary search algorithm by flipping direction of search in case left and right bounds are flipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-discussionCategory: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions