Skip to content

Implement "intersection lifetimes" to improve diagnostics and accept rare impl trait cases #89394

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:

  1. add intersection lifetimes to mir borrowck, without actually creating them
  2. specifically create them for member constraints that would otherwise be unresolvable
  3. put a lot of effort into making the diagnostics comprehensible

Some details: https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/member.20constraints.20PR.20.2389056/near/255496552

Related (purely diagnostics) PR: #89327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions