rust icon indicating copy to clipboard operation
rust copied to clipboard

Enforce predicates which link bivariant opaque lifetimes

Open compiler-errors opened this issue 1 year ago • 0 comments

During predicates_of, we install outlives obligations which link the bivariant lifetimes of an opaque to their invariant (captured) copies. During NLL, we don't enforce well-formedness of an opaque that we are trying to define, and therefore we never actually enforce that these lifetimes are equal. This means that we have strange errors (#122307), or ICEs (#121512) from unconstrained lifetimes that should be constrained.

Fix this by requiring the opaque in add_item_bounds_for_hidden_type to be well-formed, which will enforce its own predicates.

r? @aliemjay cc @lcnr @oli-obk

You have any thoughts about this approach? I guess f72f5d8f3f04798751e6d2334c8efface8a6b799 is unnecessary, because it's still possible to ICE with RPITs and uncaptured lifetimes, e.g.

fn test<'a: 'a>() -> impl Sized {
    let _: () = test::<'a>();
}

side-note: I'm feeling a déjà-vu writing this PR, like this has been attempted before... if it has, could you remind me where this was, and why this approach ultimately wasn't taken?

compiler-errors avatar Mar 10 '24 21:03 compiler-errors