Skip to content

core::iter::ArrayChunks does not return the remainder if None is never yielded #123333

Closed
@jwong101

Description

@jwong101

I tried this code:

#![feature(iter_array_chunks)]


fn main() {
    let x = [1].into_iter().array_chunks::<2>();
    let x = x.into_remainder();
    assert!(x.is_some());
}

I expected to see this happen:
There should be a remainder as 1 will not be yielded.

Instead, this happened:

   Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.47s
     Running `target/debug/playground`
thread 'main' panicked at src/main.rs:7:5:
assertion failed: x.is_some()

If this is intended behavior, then it should probably be documented, as the current documentation of ArrayChunks::into_remainder states that it:

Returns an iterator over the remaining elements of the original iterator that are not going to be returned by this iterator. The returned iterator will yield at most N-1 elements.

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (805813650 2024-03-31)
binary: rustc
commit-hash: 805813650248c1a2f6f271460d728d1bb852d2a7
commit-date: 2024-03-31
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-libsRelevant to the library 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