Skip to content

Iterator not found for referenced box array item #164751

Closed as not planned
Closed as not planned

Description

@chokomancarr

Code

I tried this code:

#[derive(Clone, Copy)]
pub struct Wrapper<T>(T);

impl<T> IntoIterator for Wrapper<T> {
    type Item = T;
    type IntoIter = std::option::IntoIter<T>;
    fn into_iter(self) -> Self::IntoIter {
        Some(self.0).into_iter()
    }
}

#[unsafe(no_mangle)]
fn test(v: &Box<[Wrapper<usize>; 2]>) {
    for v in v.into_iter().flatten() {
        std::hint::black_box(v);
    }
}

I expected to see this happen: code compiles

Instead, this happened: compile error

error[E0277]: `&Wrapper<usize>` is not an iterator
  --> <source>:14:28
   |
14 |     for v in v.into_iter().flatten() {
   |                            ^^^^^^^ `&Wrapper<usize>` is not an iterator
   |
   = help: the trait `Iterator` is not implemented for `&Wrapper<usize>`
help: the trait `IntoIterator` is implemented for `Wrapper<T>`

Version it worked on

It most recently worked on: 1.98

Version with regression

Compile errors on all the following: 1.99.0, 1.99.1, beta, nightly

Notes

It seems to only occer when the type is &Box<[Wrapper<_>; _]>.
The following all errors on 1.98: &[Wrapper<_>], &[Wrapper<_>; _], &Box<[Wrapper<_>]>.
Bug does not occur (compile succeeds) if the Box isnt behind a reference.

@rustbot modify labels: +regression-from-stable-to-{channel} -regression-untriaged

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 22, 2026
  2. rustbot commented on Oct 22, 2026

    @rustbot
    Collaborator

    Error: Unknown labels: regression-from-stable-to-{channel}

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 22, 2026
  4. theemathas commented on Oct 22, 2026

    @theemathas
    Contributor

    Presumably caused by #134021

    The v.into_iter() is now calling the IntoIter implementation on the &Box<[_; _]> instead of on the [_; _]

  5. chokomancarr commented on Oct 22, 2026

    @chokomancarr
    Author

    nevermind, looks like this is caused by the stabilized IntoIterator for boxed array

  6. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 22, 2026
  7. theemathas commented on Oct 22, 2026

    @theemathas
    Contributor

    A crater run for that PR was done, and the small amount of breakage was accepted.

  8. theemathas commented on Oct 22, 2026

    @theemathas
    Contributor

    @chokomancarr I believe the relevant impl is on &Box<[_; _]>, not on Box<[_; _]>

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

    C-bugCategory: This is a bug.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions