Skip to content

Calling into_iter on an oversized array only triggers into_iter_on_ref #4492

Open
@Nemo157

Description

@Nemo157

When using into_iter on an array within the size limits of the current impl IntoIterator for &[T; _] implementations you get a deny-by-default lint failure:

error: this .into_iter() call is equivalent to .iter() and will not move the array
 --> src/main.rs:2:22
  |
2 |     for _ in [0; 32].into_iter() {
  |                      ^^^^^^^^^ help: call directly: `iter`
  |
  = note: `#[deny(clippy::into_iter_on_array)]` on by default

If you increase the array size past those provided implementations you instead get a warn-by-default lint:

warning: this .into_iter() call is equivalent to .iter() and will not move the slice
 --> src/main.rs:2:22
  |
2 |     for _ in [0; 33].into_iter() {
  |                      ^^^^^^^^^ help: call directly: `iter`
  |
  = note: `#[warn(clippy::into_iter_on_ref)]` on by default

It seems both of these cases would be affected equally by a future const-generic powered impl<T, const N: usize> IntoIterator for [T; N].

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions