Skip to content

Incorrect note for expected type in E0271 when using an associated type #64760

Closed

Description

@ohadravid

With the following code:

#[derive(Debug)]
struct Data {}


fn do_stuff<'a>(iterator: impl Iterator<Item = &'a Data>) {
    for item in iterator {
        println!("{:?}", item)
    }
}


fn main() {
    let v = vec![Data {}];
    
    do_stuff(v.into_iter());
}

the diagnostic (in nightly & stable) wrongly complains about the expected type:

error[E0271]: type mismatch resolving `<std::vec::IntoIter<Data> as std::iter::Iterator>::Item == &Data`
  --> src/main.rs:15:5
   |
5  | fn do_stuff<'a>(iterator: impl Iterator<Item = &'a Data>) {
   |    --------                             --------------- required by this bound in `do_stuff`
...
15 |     do_stuff(v.into_iter());
   |     ^^^^^^^^ expected struct `Data`, found &Data
   |
   = note: expected type `Data`
              found type `&Data`

It should be the reversed.
This makes it difficult to understand that the into_iter should be changed to iter.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Sep 25, 2019
  2. added
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 25, 2019
  3. estebank commented on Sep 26, 2019

    @estebank
    Contributor
  4. added
    D-inconsistentDiagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    and removed
    D-inconsistentDiagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.
    on Oct 18, 2019
  5. added 2 commits that reference this issue on Oct 31, 2019
    07b6b70
    959a563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions