Skip to content

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

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

Open
fmease opened this issue May 28, 2025 · 1 comment
Open
Labels
A-associated-items Area: Associated items (types, constants & functions) A-GATs Area: Generic associated types (GATs) A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-lifetimes Area: Lifetimes / regions C-discussion Category: Discussion or questions that doesn't represent real issues. P-low Low priority T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented May 28, 2025

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):

// This corresponds to a type like `<() as Trait<'a, T>>::Type`.
// We only use the explicit predicates of the trait but
// not the ones of the associated type itself.

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!
@fmease fmease added A-lifetimes Area: Lifetimes / regions P-low Low priority A-associated-items Area: Associated items (types, constants & functions) C-discussion Category: Discussion or questions that doesn't represent real issues. T-types Relevant to the types team, which will review and decide on the PR/issue. A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-GATs Area: Generic associated types (GATs) labels May 28, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 28, 2025
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 28, 2025
@fmease
Copy link
Member Author

fmease commented May 28, 2025

Similarly ofc here:

struct Env<'a, T: Trait<'a>>(<T as Trait<'a>>::T); //~ ERROR the parameter type `T` may not live long enough
trait Trait<'a> { type T where Self: 'a; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-GATs Area: Generic associated types (GATs) A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-lifetimes Area: Lifetimes / regions C-discussion Category: Discussion or questions that doesn't represent real issues. P-low Low priority T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants