Closed
Description
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
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.
Metadata
Metadata
Assignees
Labels
Area: Non-lexical lifetimes (NLL)Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.