rust-lang / rust-lang/rust

We don't imply outlives-bounds from the own explicit bounds of a GAT projection

Open
#141,692 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-GATs A-implied-bounds A-lifetimes C-discussion P-low T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Not sure if worth tracking/discussing. I'm basically revisiting this because of IATs and LTAs. I know that T-types would like to avoid implying outlives-bounds in more places and under more circumstances at least until various soundness issues related to them have been fixed (LTAs prolly being the exception) (via: #t-types > implied bounds for the more recent features? @ 💬 (2023)).

Presently, when inferring outlives-bounds we only consider the explicit predicates of the corresp. trait when looking at projections as noted by this comment (which was written by me):

https://github.com/rust-lang/rust/blob/77101febcc9662a076ff43887497cd5b30674d93/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs#L207-L209

This means:

trait Trait<'a, T: 'a> { type Project; }
impl<'a, T: 'a> Trait<'a, T> for () { type Project = (); }

struct Env<'a, T>(<() as Trait<'a, T>>::Project);
//                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ from this projection, we imply `T: 'a`

//fn env<'a, T>() { let _: Env<'a, T>; } //~ ERROR the parameter type `T` may not live long enough
trait Trait { type Project<'a, T: 'a>; }
impl Trait for () { type Project<'a, T: 'a> = (); }

struct Env<'a, T>(<() as Trait>::Project<'a, T>); //~ ERROR the parameter type `T` may not live long enough
//                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ we **don't** imply anything from this projection!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs around lines 207–209, then compare the two GAT projection examples in the issue. Trace how explicit predicates from the corresponding trait are considered for projections and verify the current diagnostics with focused compiler tests. Done means the intended outlives-bound behavior is decided and covered by tests, accounting for the linked IAT, LTA, and soundness context.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.