Skip to content

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

Closed
@scottmcm

Description

@scottmcm
Member

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)?

Activity

cuviper

cuviper commented on Jun 9, 2017

@cuviper
Member

From what I saw on #42514, the upper bound can also be one too high. That's less problematic, I suppose, although the proposal to "just not add one" should not apply to the upper bound since then it would be too low in some cases.

Of course, it's a bit moot since this is now deprecated and expected to be removed soon. :)

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Jun 23, 2017
added a commit that references this issue on Jul 4, 2017

Auto merge of #43012 - scottmcm:delete-range-step-by, r=alexcrichton

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

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

      Participants

      @cuviper@Mark-Simulacrum@scottmcm

      Issue actions

        Incorrect lower bound from StepBy<A, RangeInclusive<A>>::size_hint · Issue #41477 · rust-lang/rust