Skip to content

Add must_use and FusedIterator to the array window adaptors - #1129

Open
youdie006 wants to merge 1 commit into
rust-itertools:masterfrom
youdie006:array-windows-must-use-fused
Open

youdie006 wants to merge 1 commit into
rust-itertools:masterfrom
youdie006:array-windows-must-use-fused

Conversation

@youdie006

Copy link
Copy Markdown

CONTRIBUTING.md:37 asks every adaptor struct for #[must_use = "iterator adaptors are lazy and do nothing unless consumed"], and :148 asks for FusedIterator on every iterator that keeps returning None. ArrayWindows and CircularArrayWindows have neither, and they are the only public adaptor structs in that position.

The tuple analogues already do: TupleWindows at src/tuple_impl.rs:164 and :231, CircularTupleWindows at :245 and :298. Both array types hold a Fuse<I> (src/array_impl.rs:15, :104), so they genuinely never yield Some after None.

The timeline explains it rather than blaming anyone: the must_use sweep in #794 merged in 2023, and src/array_impl.rs arrived in 2026 with #1086, after it.

What changes for a caller:

fn needs_fused<T: FusedIterator>(_: T) {}
needs_fused([1, 2, 3].into_iter().array_windows::<2>());

does not compile on master (the trait bound ... FusedIterator is not satisfied, twice) and compiles with this. And iter.array_windows::<2>(); as a statement is currently silent.

Verification

Base fd61933.

row src/array_impl.rs md5 T: FusedIterator bound #![deny(unused_must_use)] probe
master 3280744618 2 trait errors, nothing runs 1 error (TupleWindows)
this PR 1e83c4a3c5 compiles, 1 test ran, ok 3 errors (both array types plus TupleWindows)
FusedIterator only 62800dda97 compiles, ok 1 error
must_use only e591ff4370 2 trait errors 3 errors

Each half removed alone is caught by a different probe. TupleWindows appears unchanged in all four rows, which is the control that the probes are measuring what I think.

Gates as .github/workflows/ci.yml writes them: cargo fmt --check clean; cargo test --all-features 14 result blocks, 0 failures; cargo +1.63.0 no-dev-deps check (the MSRV job, exact command) exit 0. RUSTFLAGS="--deny warnings" cargo clippy --all-features fails, identically on an unmodified tree, on clippy::question_mark in src/lib.rs, src/adaptors/mod.rs and src/multipeek_impl.rs; src/array_impl.rs does not appear in either error list. That is open PR #1128.

The fused_array_windows row in tests/quick.rs follows the 17 existing fused_* rows, but is_fused is a runtime check and these adaptors already behave fused, so that row passes on master too. It documents the behaviour rather than guarding the impls; the trait bound above is what actually diverges. Happy to drop it if you would rather not have a row that cannot fail.

#1118 is open on this file adding size_hint and ExactSizeIterator; the hunks are adjacent but distinct, and I have not touched either.


Disclosure: written with the help of Claude (an AI assistant). Every result above is from runs on my machine.

ArrayWindows and CircularArrayWindows are the only public adaptor structs
with neither, so dropping one is silent and neither can satisfy a
T: FusedIterator bound. Both already hold a Fuse<I>, and the tuple
analogues TupleWindows and CircularTupleWindows carry both.
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

Successfully merging this pull request may close these issues.

1 participant