Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ilyvion opened this issue Aug 16, 2023 · 2 comments
Closed

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

ilyvion opened this issue Aug 16, 2023 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ilyvion
Copy link

ilyvion commented Aug 16, 2023

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.

@ilyvion ilyvion added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 16, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 16, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 4, 2023
@chenyukang
Copy link
Member

Now it's output is:

error[E0308]: mismatched types
  --> ./t/t6.rs:16:5
   |
16 |     receive(function2);
   |     ^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected reference `&'a _`
              found reference `&_`
note: the lifetime requirement is introduced here
  --> ./t/t6.rs:11:8
   |
11 |     T: Trait<A>,
   |        ^^^^^^^^

error: aborting due to 1 previous error

@chenyukang
Copy link
Member

please reopen it if there is more question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants