Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecatedStepBy<A, RangeInclusive<A>> gives bad size hints #42514

Closed
cuviper opened this issue Jun 7, 2017 · 2 comments
Closed

DeprecatedStepBy<A, RangeInclusive<A>> gives bad size hints #42514

cuviper opened this issue Jun 7, 2017 · 2 comments

Comments

@cuviper
Copy link
Member

cuviper commented Jun 7, 2017

DeprecatedStepBy being the old unstable core::iter::range::StepBy. cc #27741

Its size_hint over-optimistically adds 1 to Step::steps_between. That works if the step exactly lands on the end condition, a perfect multiple, but otherwise:

    let i = (0...9).step_by(2);
    let v: Vec<_> = i.clone().collect();
    assert_eq!(v.len(), 5); // OK
    assert_eq!(i.size_hint(), (5, Some(5))); // FAILED, gives `(6, Some(6))`

Or if the iterator is already exhausted:

    let mut i = (0...9).step_by(2);
    let v: Vec<_> = i.by_ref().collect();
    assert_eq!(v.len(), 5); // OK
    assert_eq!(i.size_hint(), (0, Some(0))); // FAILED, gives `(1, Some(1))`

At least it doesn't implement TrustedLen.

@scottmcm
Copy link
Member

scottmcm commented Jun 9, 2017

Dup of #41477?

@cuviper
Copy link
Member Author

cuviper commented Jun 9, 2017

Yep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants