Skip to content

&Box<[T]> does not impl IntoIterator #83589

Open
@lopopolo

Description

I tried this code:

fn one() {
    let v = vec![1, 2, 3].into_boxed_slice();
    for elem in &v {
        println!("elem: {}", elem);
    }
}

fn two() {
    let v = vec![1, 2, 3].into_boxed_slice();
    for elem in &*v {
        println!("elem: {}", elem);
    }
}

I expected to see this happen: I expected both functions one and two to compile.

Instead, this happened: function one does not compile:

   Compiling playground v0.0.1 (/playground)
error[E0277]: `&Box<[{integer}]>` is not an iterator
 --> src/lib.rs:4:17
  |
4 |     for elem in &v {
  |                 ^^ `&Box<[{integer}]>` is not an iterator
  |
  = help: the trait `Iterator` is not implemented for `&Box<[{integer}]>`
  = note: required because of the requirements on the impl of `IntoIterator` for `&Box<[{integer}]>`
  = note: required by `into_iter`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=93a16fe1e2860bd5eb98b2d73f00fc50

Meta

rustc --version --verbose:

Stable channel
Build using the Stable version: 1.51.0

Metadata

Assignees

No one assigned

    Labels

    A-boxArea: Our favorite opsem complicationA-iteratorsArea: IteratorsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API 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