Skip to content

Incorrect lower bound on size hint for <[T]>::splitn if n==0 #87978

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

Closed
steffahn opened this issue Aug 12, 2021 · 0 comments · Fixed by #87974
Closed

Incorrect lower bound on size hint for <[T]>::splitn if n==0 #87978

steffahn opened this issue Aug 12, 2021 · 0 comments · Fixed by #87974
Labels
A-iterators Area: Iterators A-slice Area: `[T]` C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

I’m creating this issue in order to better document the bug in std that #87974 fixes once it’s merged.

fn this_should_hold_for_non_buggy_iterators(i: impl Iterator) {
    let (lower_hint, count) = dbg!(i.size_hint().0, i.count());
    assert!(lower_hint <= count)
}

fn main() {
    this_should_hold_for_non_buggy_iterators([()].splitn(0, |_| false));
    // [src/main.rs:3] i.size_hint().0 = 1
    // [src/main.rs:3] i.count() = 0
    // thread 'main' panicked at 'assertion failed: lower_hint <= count', src/main.rs:4:5
}

(playground)

@rustbot label T-libs, A-slice, A-iterators

@steffahn steffahn added the C-bug Category: This is a bug. label Aug 12, 2021
@rustbot rustbot added A-iterators Area: Iterators A-slice Area: `[T]` T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 12, 2021
@bors bors closed this as completed in 40db258 Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-iterators Area: Iterators A-slice Area: `[T]` C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants