The following program compiles successfully:
fn impossible() where for<'a> &'a (): 'static {
}
fn main() {}
The where clause on impossible is impossible to satisfy, since it is not the case that every choice of 'a outlives 'static. However, we never call impossible, so this program compiles (similar to an unsatisfiable trait bound like where String: Copy).
If we add a closure to the function:
fn impossible() where for<'a> &'a (): 'static {
let _ = || {};
}
fn main() {}
then it stops compiling (note that this occurs both with and without #![feature(nll)]):
error: higher-ranked lifetime error
--> src/main.rs:2:13
|
2 | let _ = || {};
| ^^^^^
|
= note: could not prove for<'a> &'a (): 'static
error: could not compile `playground` due to previous error
The issue occurs here:
|
tcx.predicates_of(def_id).instantiate(tcx, substs) |
When we instantiate the predicates of the closure during type-checking of impossible, we also instantiate the predicates for the parent of the closure - that is, the predicates of impossible. This results in us trying to prove that for<'a> &'a (): 'static holds, leading to an error. Normally, we will not try to prove this predicate during type-checking of impossible itself.
The following program compiles successfully:
The
whereclause onimpossibleis impossible to satisfy, since it is not the case that every choice of'aoutlives'static. However, we never callimpossible, so this program compiles (similar to an unsatisfiable trait bound likewhere String: Copy).If we add a closure to the function:
then it stops compiling (note that this occurs both with and without
#![feature(nll)]):The issue occurs here:
rust/compiler/rustc_borrowck/src/type_check/mod.rs
Line 2688 in 6dc08b9
When we instantiate the predicates of the closure during type-checking of
impossible, we also instantiate the predicates for the parent of the closure - that is, the predicates ofimpossible. This results in us trying to prove thatfor<'a> &'a (): 'staticholds, leading to an error. Normally, we will not try to prove this predicate during type-checking ofimpossibleitself.