Skip to content

Step::steps_between does not distinguish overflow and unimplemented (unstable) #48117

Open
@scottmcm

Description

@scottmcm

It returns Option<size>: https://doc.rust-lang.org/std/iter/trait.Step.html#tymethod.steps_between

And the comment says it uses None for overflow: https://doc.rust-lang.org/src/core/iter/range.rs.html#29

But it also uses None for unimplemented https://doc.rust-lang.org/src/core/iter/range.rs.html#155

And as a result, Range needs to return (0, None) when it gets None: https://doc.rust-lang.org/src/core/iter/range.rs.html#235-240

It would be nice to either

  • Require that the method is implemented accurately (easy for fundamental integers; harder if Step is expected to support graph walks, but maybe not harder than PartialOrd)
  • Change the type to something else, maybe Option<Option<usize>> or be more hint-like with (usize, Option<usize>)
  • Something else

cc #42168

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API 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