-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
refactor impl trait to model abstract type a bit better #44727
Copy link
Copy link
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-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.
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-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
Fields
Give feedbackNo fields configured for issues without a type.
After some discussion with @cramertj, I wanted to write up a rough idea for how to represent
impl Traitin the HIR etc. The key idea is to move towards a place where we represent theabstract typethat animpl Traitconceptually desugars to as a distinct "item" in the HIR.Today, for each usage of
impl Trait, we create a def-id, which basically represents theabstract typebehind theimpl Trait. However, in the HIR itself, we continue to mirror the syntax, so for example the variant forImplTraitincludes the bounds listed inline. This is not I think what we really want.The refactoring then is to do the following:
hir::Cratea "abstract type" vector sort of like the list of bodies.hir::AbstractTypestruct that contains the following:ImplTraitvariant ofhir::Tywith to include a "list of substs" in some form (and not have bounds)impl trait, we create and push ahir::AbstractType:ast::Tyinto thehir::AbstractTypehir::ImplTrait(DefId, [T, 'a])where the "substs" are references to all the lifetimse/types in scope (I'm not entirely sure how best to represent and synthesize those?)