Make RPITITs inherit the assumed_wf_types
of their parent method by compiler-errors · Pull Request #113704 · rust-lang/rust (original) (raw)
... and then move the RPITIT well-formedness check to just use the regular logic of wfchecking an associated type.
We need to inherit the assumed_wf_types
of the RPITIT's parent function in order for the given code to be considered well-formed:
trait Foo { fn bar<'a, T>(_: &'a T) -> impl Iterator<Output = &'a T>; }
Since for &'a T
to be WF, we need T: 'a
.
In order for this to work for late-bound lifetimes, we need to do some additional mapping of any late-bound lifetimes captured by these assumed wf types. This is because within the body of the function (and thus in the assumed_wf_types
), they're represented as ReFree
variants of the original late-bound lifetimes declared in the function's generics, but in the RPITIT's GAT, they're represented as "reified" ReEarlyBound
vars (duplicated during opaque type lowering). Luckily, the mapping between these two is already stored in the opaque.
Fixes #113796