Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SkiFire13 opened this issue Jul 14, 2021 · 5 comments
Labels
C-bug Category: This is a bug. P-low Low priority regression-untriaged Untriaged performance or correctness regression.

Comments

@SkiFire13
Copy link
Contributor

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`.
@SkiFire13 SkiFire13 added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jul 14, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 14, 2021
@jyn514
Copy link
Member

jyn514 commented Jul 14, 2021

Is this an issue in practice? Does it break any crates on crates.io?

@SkiFire13
Copy link
Contributor Author

As previously stated I discovered this by seeing #84147, not due to some crate suddently not compiling anymore, and since the setup needed is pretty niche I don't think this is a big issue in practice.

@jonas-schievink
Copy link
Contributor

The workaround was added specifically to fix array.into_iter(), which some crates in the crater run were doing. I don't think any crates were found that relied on this behavior.

@apiraino
Copy link
Contributor

Assigning priority, Zulip discussion of the Prioritization Working Group in case this should be re-evaluated

@rustbot label -I-prioritize +P-low

@rustbot rustbot added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 22, 2021
@jyn514
Copy link
Member

jyn514 commented Jul 22, 2021

I don't think this is worth tracking.

@jyn514 jyn514 closed this as completed Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-low Low priority regression-untriaged Untriaged performance or correctness regression.
Projects
None yet
Development

No branches or pull requests

5 participants