Skip to content

Poor error message with associated constrained trait type #57663

Closed
@hellow554

Description

@hellow554
trait Bar {
    type Ok;
    type Sibling: Bar2<Ok=Self::Ok>;
}
trait Bar2 {
    type Ok;
}

struct Foo;
struct Foo2;

impl Bar for Foo {
    type Ok = ();
    type Sibling = Foo2;
}
impl Bar2 for Foo2 {
    type Ok = u32; // <- `u32` instead of `()`
}

(Playground)

Errors:

error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
  --> src/lib.rs:14:6
   |
14 | impl Bar for Foo {
   |      ^^^ expected u32, found ()
   |
   = note: expected type `u32`
              found type `()`

I don't like the error message, I would like to see something similar to this

error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
...

LN | type Ok = ();
   | ^^^^^^^^^^^^ associated type Ok defined here
LN | type Sibling: Bar2<Ok=Self::Ok>;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type constrained here
   | ...
LN | type Ok = u32; // <- `u32` instead of `()`
   | ^^^^^^^^^^^^^ type violated here

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.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