Verify safety of slice iterator functions (Challenge 18) #545
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Solves Challenge 18 — Verify the safety of
sliceiter functions.Part 1:
iterator!macro functions (macros.rs)All 16 macro-generated functions verified for both
IterandIterMut:make_slice,len,is_empty,next,size_hint,count,nth,advance_by,last,fold,for_each,position,rposition,next_back,nth_back,advance_back_byUses
#[cfg(kani)]abstractions for loop-based functions (fold,for_each,position,rposition) to enable unbounded verification — each verifies a single iteration step's safety, then nondeterministically advances.Part 2: Safe and unsafe functions (iter.rs)
Unsafe
__iterator_get_unchecked— 9 contracts verified:Windows,Chunks,ChunksMut,ChunksExact,ChunksExactMut,RChunks,RChunksMut,RChunksExact,RChunksExactMutSafe functions with unsafe code — 33 functions verified including:
Iter::new,IterMut::new/into_slice/as_mut_sliceSplit::next/next_backChunks,ChunksMut,ChunksExact,ChunksExactMut,RChunks,RChunksMut,RChunksExact,RChunksExactMut,ArrayWindows)Verification approach
isize::MAX,u8withu32::MAX)()(ZST),u8(1-byte),char(4-byte with validity),(char, u8)(compound with padding)Resolves #282
🤖 Generated with Claude Code