a-mir-formality icon indicating copy to clipboard operation
a-mir-formality copied to clipboard

early- vs late-bound lifetimes

Open nikomatsakis opened this issue 3 years ago • 0 comments

We have to figure out how to model early- vs late-bound lifetimes.

I believe that we should be able to erase the distinction in a-mir-formality (and, hopefully, eventually in rustc as well). The idea would be that all parameters can become late-bound, because we can now support types that are fully quantified over types and lifetimes. I think this is the basic approach we should take.

However, to maintain compatibility with rustc, we want to make it so that, at MIR time, some set of those parameters become "fixed". Consider a case like this, which compiles in rustc today...

fn foo<T>(t: T) { }
fn main() {
    let f = foo; // f: foo<?T>
    f(None); // ?T = Option<?U>
    f(Some(22)); // ?U = i32
}

...under the model I'm proposing, each call to f would be independent, and so the f(None) call would need to be written f(None::<i32>). I think that we should write an RFC that changes rust's behavior to match (perhaps in Rust 2024) but in the meantime I'd like to be able to model both variants in a-mir-formality.

Anyway, this is a bit of an "open-ended" issue without a clear path to solution--- we're not ready to tackle this yet. Some other considerations:

  • in rustc, impls can have more/different late-bound lifetimes vs the trait (https://github.com/nikomatsakis/a-mir-formality/pull/70 requires that the have precisely the same lifetime parameters).

nikomatsakis avatar Jun 25 '22 10:06 nikomatsakis