-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.P-lowLow priorityLow priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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):
rust/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Lines 207 to 209 in 77101fe
// 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!
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.P-lowLow priorityLow priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.