Skip to content

Incorrect lower bound from StepBy<A, RangeInclusive<A>>::size_hint #41477

Closed
@scottmcm

Description

@scottmcm

Repro: https://is.gd/nFIian (tried 2017-04-21)

#![feature(step_by)]
#![feature(inclusive_range_syntax)]

fn main() {
    let i = (0...10).step_by(3);
    assert!(i.size_hint().0 <= i.count());
}

Looks like the implementation is adding one to the Range (exclusive) lower bound, which is incorrect when the size of the base range isn't a multiple of the step.

Thoughts on whether it'd be a better fix to just not add one (correct, but a less-helpful hint) or to add one to end before calling Step::steps_between (better hint, more math and more overflow cases)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    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