Skip to content

Expected and found traits show as identical for this code #114883

Closed
@ilyvion

Description

@ilyvion

Code

trait Trait<A> {}

impl<T, A, O> Trait<A> for T where for<'a> T: Fn(&'a A) -> O + 'a {}

fn function2(value: &u32) -> &u32 {
    value
}

fn receive<T, A>(_: T)
where
    T: Trait<A>,
{
}

fn main() {
    receive(function2);
}

Current output

error[E0308]: mismatched types
  --> src/main.rs:16:5
   |
16 |     receive(function2);
   |     ^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected trait `for<'a> <for<'a> fn(&'a u32) -> &'a u32 {function2} as FnOnce<(&'a u32,)>>`
              found trait `for<'a> <for<'a> fn(&'a u32) -> &'a u32 {function2} as FnOnce<(&'a u32,)>>`
note: the lifetime requirement is introduced here
  --> src/main.rs:11:8
   |
11 |     T: Trait<A>,
   |        ^^^^^^^^

Desired output

The expected trait and found trait lines are identical, which is incredibly confusing when it comes to finding out what's wrong here. I would have expected the output to actually show what the difference is.

Rationale and extra context

No response

Other cases

No response

Anything else?

Feel free to update the title to something more precise if you know what underlying issues is going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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