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

InclusiveRange's size_hint can give 1 when empty, despite implementing TrustedLen #42135

Closed
scottmcm opened this issue May 21, 2017 · 1 comment
Labels
I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

Repro:

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

use std::iter::TrustedLen;

fn check_size_correctness<T:TrustedLen+ExactSizeIterator>(x: T) {
    let len = x.len();
    assert_eq!(x.count(), len);
}

fn main() {
    check_size_correctness(100...0u8);
}

#42134 will fix this, but I wanted to record it because I think TrustedLen being an unsafe trait means this could be leading to unsoundness.

@nagisa nagisa added I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. I-nominated labels May 21, 2017
@scottmcm scottmcm changed the title InclusiveRange's size_hint is wrong, despite implementing TrustedLen InclusiveRange's size_hint can give 1 when empty, despite implementing TrustedLen May 21, 2017
@alexcrichton
Copy link
Member

cc #42134, a fix

@bors bors closed this as completed in 7eaca60 May 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants