Skip to content

NLL accepts higher-ranked subtype that non-NLL rejects #57642

Description

@matthewjasper

The following code example (playground)

// #![feature(nll)]

trait X {
    type G;
    fn make_g() -> Self::G;
}

impl<'a> X for fn(&'a ()) {
    type G = &'a ();

    fn make_g() -> Self::G {
        &()
    }
}

trait Y {
    type F;
    fn make_f() -> Self::F;
}

impl<T> Y for fn(T) {
    type F = fn(T);
    
    fn make_f() -> Self::F {
        |_| {}
    }
}

// Always an error, but the message is bad
fn higher_ranked_region_has_lost_its_binder() {
    let x = <fn (&())>::make_g();
}

// Works, but only with feature(nll)
fn magical() {
    let x = <fn (&())>::make_f();
}

produces the output

Details
error[E0308]: mismatched types
  --> src/lib.rs:31:13
   |
31 |     let x = <fn (&())>::make_g();
   |             ^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `X`
              found type `X`

error[E0308]: mismatched types
  --> src/lib.rs:36:13
   |
36 |     let x = <fn (&())>::make_f();
   |             ^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `Y`
              found type `Y`

The second example also unexpectedly compiles in full NLL mode.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityT-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