Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function with impossible-to-satisfy higher-ranked bound triggers error when a closure is present #89409

Open
Aaron1011 opened this issue Sep 30, 2021 · 0 comments
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: lifetime related C-bug Category: This is a bug.

Comments

@Aaron1011
Copy link
Member

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.

@Aaron1011 Aaron1011 added A-lifetimes Area: lifetime related A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. labels Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: lifetime related C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant