Open
Description
TLDR: The following does not compile but it should
trait Trait<'a, 'b> {}
impl<T> Trait<'_, '_> for T {}
struct Struct<'a>(&'a u8);
fn foo<'a, 'b>(a: Struct<'a>, b: Struct<'b>) -> impl Trait<'a, 'b> {
if false { a } else { b }
}
The lifetime of the if false { a } else { b }
is 'a
OR 'b
, but right now we can only express 'a
AND 'b
(as 'lifetime: 'a + 'b
).
Beyond diagnostics, only impl trait can actually encounter such lifetimes in a somewhat reasonable way.
So the plan is as follows:
- add intersection lifetimes to mir borrowck, without actually creating them
- specifically create them for member constraints that would otherwise be unresolvable
- put a lot of effort into making the diagnostics comprehensible
Related (purely diagnostics) PR: #89327