Skip to content

array_into_iter does not trigger for existing trait impl #88475

Closed
@ehuss

Description

@ehuss

I tried this code:

#![allow(unused)]

struct FooIter;

trait MyIntoIter {
    fn into_iter(self: Self) -> FooIter;
}

impl<T, const N: usize> MyIntoIter for [T; N] {
    fn into_iter(self: Self) -> FooIter {
        FooIter
    }
}

struct Point;

pub fn foo() {
    let points: [Point; 1] = [Point];
    let y = points.into_iter();
}

This code will not emit the array_into_iter lint. When updating to the 2021 edition, the code fails to compile:

error[E0034]: multiple applicable items in scope
  --> src/lib.rs:19:20
   |
19 |     let y = points.into_iter();
   |                    ^^^^^^^^^ multiple `into_iter` found
   |
note: candidate #1 is defined in an impl of the trait `MyIntoIter` for the type `[T; N]`
  --> src/lib.rs:10:5
   |
10 |     fn into_iter(self: Self) -> FooIter {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: candidate #2 is defined in an impl of the trait `IntoIterator` for the type `[T; N]`
help: disambiguate the associated function for candidate #1
   |
19 |     let y = MyIntoIter::into_iter(points);
   |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
   |
19 |     let y = IntoIterator::into_iter(points);
   |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I would expect the array_into_iter lint to give the appropriate suggestion.

Found in the 2021 crater run for:

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (5eacec9ec 2021-08-28)
binary: rustc
commit-hash: 5eacec9ec7e112a0de1011519a57c45586d58414
commit-date: 2021-08-28
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2021Area: The 2021 editionA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions