Skip to content

“expected” and “found” interchanged in error message E0308 #57226

Closed

Description

@gralpli

I’m using rustc 1.33.0-nightly (a2b0f247b 2018-12-30).

trait MyTrait {
    type Item;
}

struct MyStruct<T> {
    item: T
}

impl<T> MyTrait for MyStruct<T> {
    type Item = T;
}

fn func<T: MyTrait<Item=i32>>(t: T) { }

fn main() {
    func(MyStruct { item: "str" });
}

func expects an MyTrait<Item=i32>, so the error message should say: “expected type i32, found type &str.” Instead, they’re interchanged and it says:

error[E0271]: type mismatch resolving `<MyStruct<&str> as MyTrait>::Item == i32`
  --> src/main.rs:17:5
   |
17 |     func(my_struct);
   |     ^^^^ expected &str, found i32
   |
   = note: expected type `&str`
              found type `i32`
note: required by `func`
  --> src/main.rs:13:1
   |
13 | fn func<T: MyTrait<Item=i32>>(t: T) { }
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Activity

  1. estebank commented on Sep 26, 2019

    @estebank
    Contributor

    Current output:

    error[E0271]: type mismatch resolving `<MyStruct<&str> as MyTrait>::Item == i32`
      --> src/main.rs:16:5
       |
    13 | fn func<T: MyTrait<Item=i32>>(t: T) { }
       |    ----            -------- required by this bound in `func`
    ...
    16 |     func(MyStruct { item: "str" });
       |     ^^^^ expected &str, found i32
       |
       = note: expected type `&str`
                  found type `i32`
    

    Still same reversal.

  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 10, 2019
  3. added
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    on Oct 18, 2019
  4. 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 lintsD-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