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.
The following code example (playground)
produces the output
Details
The second example also unexpectedly compiles in full NLL mode.