Description
I'm working on #56238. In the process, I'm extending how impl Trait
lifetime inference works -- in particular in scenarios involving multiple, unrelated lifetimes, such as impl Trait<'a, 'b>
. The challenge here is that each region 'h
in the hidden type must be equal to 'a
or 'b
, but we can't readily express that relationship in terms of our usual "outlives relationships". The solver is thus extended with a "pick constraint", written pick 'h from ['a, 'b]
, which expresses that 'h
must be equal to 'a
or 'b
. The current integration into the solver, however, requires that the regions involved are lifetime parameters. This is always true for impl Trait
used at function boundaries, but it is not true for let bindings.
The challenge is that if you have a program like:
#![feature(impl_trait_in_bindings)]
trait Foo<'a> { }
impl Foo<'_> for &u32 { }
fn main() {
let _: impl Foo<'_> = &44; // let's call the region variable for `'_` `'1`
}
then we would wind up with pick '0 from ['1, 'static]
, where '0
is the region variable in the hidden type (&'0 u32
) and '1
is the region variable in the bounds Foo<'1>
. This is tricky because both '0
and '1
are being inferred -- so making them equal may have other repercussions.
For the time being, I've chosen to include some assertions that this scenario never comes up. I'm tagging a FIXME in the code with this issue number. I was going to create some tests, but owing to the ICE #60473 (not unrelated to this issue, actually), that proved difficult, so I'll just post comments in here instead.