Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oli-obk opened this issue Sep 30, 2021 · 0 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Sep 30, 2021

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

@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) labels Sep 30, 2021
@oli-obk oli-obk self-assigned this Sep 30, 2021
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants