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

Odd error message with Iterator trait object #32627

Closed
jorendorff opened this issue Mar 30, 2016 · 3 comments
Closed

Odd error message with Iterator trait object #32627

jorendorff opened this issue Mar 30, 2016 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jorendorff
Copy link
Contributor

fn dump(iter: &Iterator<Item=i32>) {
    for s in iter {
        println!("{}", s);
    }
}

fn main() {
    let a = [1,2,3,4,5,6];
    dump(&a.iter().cloned());
}

Error output is:

<anon>:2:9: 4:10 error: the trait `core::iter::Iterator` is not implemented for the type `&core::iter::Iterator<Item=i32>` [E0277]
<anon>:2         for s in iter {
<anon>:3             println!("{}", s);
<anon>:4         }
<anon>:2:9: 4:10 help: see the detailed explanation for E0277
<anon>:2:9: 4:10 note: `&core::iter::Iterator<Item=i32>` is not an iterator; maybe try calling `.iter()` or a similar method
<anon>:2:9: 4:10 note: required by `core::iter::IntoIterator::into_iter`
error: aborting due to previous error

Adding mut to the trait object type on line 1, and the corresponding borrow on line 9, fixes it. My question is, can the error message be improved?

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label May 16, 2016
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of #32627.

@jorendorff
Copy link
Contributor Author

@Mark-Simulacrum This is #32627. Which issue did you mean to link to? :)

@Mark-Simulacrum
Copy link
Member

Ah.. #37914. GH should really warn you about this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants