Skip to content

rustc_skip_array_during_method_dispatch is bypassed by method calls implemented for any I: IntoIterator #87132

Closed
@SkiFire13

Description

@SkiFire13

After seeing #84147 I wondered if it applied to any method call that requires [T; N]: IntoIterator, but looks like that's not the case. This code compiles fine in rust 1.52, but fails to compile from rust 1.53

trait IterExt {
    type Iter: Iterator;
    fn it(self) -> Self::Iter;
}

impl<I: IntoIterator> IterExt for I {
    type Iter = I::IntoIter;
    fn it(self) -> Self::Iter {
        self.into_iter()
    }
}

fn main() {
    let a = [1, 2, 3];
    for i in a.it() {
        let _: &i32 = i;
    }
}

In rust 1.53 it fails with the following error:

error[E0308]: mismatched types
  --> <source>:16:23
   |
16 |         let _: &i32 = i;
   |                ----   ^
   |                |      |
   |                |      expected `&i32`, found integer
   |                |      help: consider borrowing here: `&i`
   |                expected due to this

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-lowLow priorityregression-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