Only determine impl-trait desugaring kind once #96529
Labels
A-ast
Area: AST
A-HIR
Area: The high-level intermediate representation (HIR)
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
E-medium
Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
E-mentor
Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
impl-trait
can either be desugared as a generic parameter (universal), as an opaque type (existential), or forbidden. This desugaring is currently on the AST in two places:def_collector
andast_lowering
. The two logic are not consistent with one another. When this happens,ast_lowering
is right.dyn Trait<T: Bound>
sometimes desugars todyn Trait<T = impl Bound>
, and sometimes does not.We should only determine the desugaring once. This can be achieved by:
def_collector
into animpl_trait_context: FxHashMap<LocalDefId, ImplTraitContext>
inResolver
;impl_trait_id: NodeId
inrustc_ast::AssocConstraint
and use it to create the impl-trait'sLocalDefId
;UniversalInDyn
to handle thedyn Trait<T: Bound>
case indef_collector
and create the definition there,desugar_to_impl_trait
should be replaced byresolver.opt_local_def_id(constraint.impl_trait_id).is_some()
;&mut Vec
inrustc_ast_lowering::ImplTraitContext
toLoweringContext
, the new field should be saved and restored bywith_hir_id_owner
;rustc_ast_lowering::ImplTraitContext
andrustc_resolve::ImplTraitContext
, introducing aResolverAstLowering::get_impl_trait_context(LocalDefId) -> Option<ImplTraitContext>
to access the information.Please reach out on Zulip for any question.
The text was updated successfully, but these errors were encountered: