Skip to content

Confusing error message associated with universe transition: "one type is more general than the other" #57362

Closed
@dtolnay

Description

@dtolnay
trait Trait {
    fn f(self);
}

impl<T> Trait for fn(&T) {
    fn f(self) {
        println!("f");
    }
}

fn main() {
    let a: fn(_) = |_: &u8| {};
    a.f();
}

Prior to #56105, the error message was:

error[E0599]: no method named `f` found for type `fn(&u8)` in the current scope
  --> src/main.rs:13:7
   |
13 |     a.f();
   |       ^
   |
   = note: a is a function, perhaps you wish to call it
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `f`, perhaps you need to implement it:
           candidate #1: `Trait`

i.e. the trait is implemented only for for<'a> fn(&'a u8) and not for a concrete fn(&'x u8).

The new error message is:

error[E0308]: mismatched types
  --> src/main.rs:13:7
   |
13 |     a.f();
   |       ^ one type is more general than the other
   |
   = note: expected type `Trait`
              found type `Trait`

I don't know what this message is trying to say.

Mentioning @nikomatsakis and @scalexm who worked on universes.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions