Skip to content

IntoIter::{as_slice, clone, ..} materialize &[T] over moved out prefix slots, leading to undefined behavior #331

Done

Description

@Snehal-Reddy

Say, T is Box<i32> which makes this UB bit more clear.

Say we do .next() a few times. Then slots 0..self.index in IntoIter are logically moved-out. Referencing them is UB i.e. holding Box pointers after drop or aliased copies of live reference)

Safe functions IntoIter::{as_slice, as_mut_slice, clone, fmt} evaluate &self.v[self.index..] or &mut self.v[self.index..]. ArrayVec does not implement Index<RangeFrom<usize>>, only slices [T] do. So before Rust can apply [self.index..], it has to convert &self.v into a &[T] via Deref::deref(&self.v). This leads to UB.

Activity

  1. added 2 commits that reference this issue on Nov 23, 2026
    5236a7d
    0a64226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions