-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Compiler incorrectly (and inconsistently) finds Iterator methods on i32 #84495
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
Comments
Some discussion on Discord suggests that impl<I: Iterator + ?Sized> Iterator for &mut I might be a culprit. Trying with the variant fn main() {
let x: i32 = 1;
println!("{:?}", x.next())
} produces
as expected. So it looks like the trait bound |
I suggest retitling this to "Compiler incorrectly (and inconsistently) finds |
Iterator
bound needed when .count()
called on i32
I'd also like to suggest adding D-newcomer-roadblock because I've seen several other newcomers on Discord run into this confusing diagnostic. |
I tried to replicate the incorrect diagnostic with a more minimal case than trait Trait {
// similar to Iterator::next
fn f1(&self);
// similar to Iterator::count
fn f2(self) where Self: Sized {}
// similar to Iterator::size_hint
fn f3(&self) {}
}
// similar to impl<T: Iterator + ?Sized> Iterator for &mut T
impl<T: Trait> Trait for &T
{
fn f1(&self) { (**self).f1() }
}
fn main() {
1i32.f1();
1i32.f2();
1i32.f3();
} produces these errors:
I've built a debugging version of the compiler and I'm trying to understand the debug logs for the trait and typechecking systems. |
To elaborate on my prior comment: newcomers seem likely to encounter and be confused by this diagnostic. I ran into it myself by trying to call @rustbot label +D-newcomer-roadblock |
…ssion-test, r=Dylan-DPC Add regression test for `<i32 as Iterator>::count` Closes rust-lang#84495
…ssion-test, r=Dylan-DPC Add regression test for `<i32 as Iterator>::count` Closes rust-lang#84495
Given the following code: playground
The current output is:
Ideally the output should look like:
For some reason, this doesn't happen for all traits in
std
. EgJust gives
playground
Version: 1.53.0-nightly (2021-04-22 7f4afdf)
The text was updated successfully, but these errors were encountered: