Skip to content

Type mismatch in a associated type bound don't point at said associated type #139531

Open
@ShE3py

Description

@ShE3py
struct Foo;
trait Bar: TryFrom<(), Error = i32> {}

impl Bar for Foo {}
impl TryFrom<()> for Foo {
    type Error = ();
    
    fn try_from(_: ()) -> Result<Self, Self::Error> {
        todo!()
    }
}

Current output:

error[E0271]: type mismatch resolving `<Foo as TryFrom<()>>::Error == i32`
 --> src/lib.rs:4:14
  |
4 | impl Bar for Foo {}
  |              ^^^ expected `i32`, found `()`
  |
note: required by a bound in `Bar`
 --> src/lib.rs:2:24
  |
2 | trait Bar: TryFrom<(), Error = i32> {}
  |                        ^^^^^^^^^^^ required by this bound in `Bar`

Desired output:

error[E0271]: type mismatch resolving `<Foo as TryFrom<()>>::Error == i32`
 --> src/lib.rs:4:14
  |
6 |     type Error = ();
  |                  ^^ expected `i32`, found `()`
  |
note: required by a bound in `Bar`
 --> src/lib.rs:2:24
  |
2 | trait Bar: TryFrom<(), Error = i32> {}
  |                        ^^^^^^^^^^^ required by this bound in `Bar`
note: required for this impl
 --> src/lib.rs:4:14
  |
4 | impl Bar for Foo {}
  | ^^^^^^^^^^^^^^^^
  |

Similar:

struct Foo;
trait Bar: TryFrom<(), Error = i32> {}

impl Bar for Foo {}
error[E0271]: type mismatch resolving `<Foo as TryFrom<()>>::Error == i32`
 --> src/lib.rs:4:14
  |
4 | impl Bar for Foo {}
  |              ^^^ expected `i32`, found `Infallible`
  |
note: required by a bound in `Bar`
 --> src/lib.rs:2:24
  |
2 | trait Bar: TryFrom<(), Error = i32> {}
  |                        ^^^^^^^^^^^ required by this bound in `Bar`

error[E0277]: the trait bound `Foo: TryFrom<()>` is not satisfied
 --> src/lib.rs:4:14
  |
4 | impl Bar for Foo {}
  |              ^^^ the trait `From<()>` is not implemented for `Foo`
  |
  = note: required for `()` to implement `Into<Foo>`
  = note: required for `Foo` to implement `TryFrom<()>`
note: required by a bound in `Bar`
 --> src/lib.rs:2:12
  |
2 | trait Bar: TryFrom<(), Error = i32> {}
  |            ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Bar`

E0271 should probably be dropped in favor of E0277 here.


@rustbot label +A-diagnostics +A-associated-items +T-compiler +D-imprecise-spans

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsD-imprecise-spansDiagnostics: spans don't point to exactly the erroneous codeT-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