Open
Description
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
and ast_lowering
. The two logic are not consistent with one another. When this happens, ast_lowering
is right.
dyn Trait<T: Bound>
sometimes desugars to dyn Trait<T = impl Bound>
, and sometimes does not.
We should only determine the desugaring once. This can be achieved by:
- saving the desugaring from
def_collector
into animpl_trait_context: FxHashMap<LocalDefId, ImplTraitContext>
inResolver
; - add
impl_trait_id: NodeId
inrustc_ast::AssocConstraint
and use it to create the impl-trait'sLocalDefId
; - introduce
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()
; - move the
&mut Vec
inrustc_ast_lowering::ImplTraitContext
toLoweringContext
, the new field should be saved and restored bywith_hir_id_owner
; - merge
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.
Metadata
Metadata
Assignees
Labels
Area: The high-level intermediate representation (HIR)Area: ASTCategory: PRs that clean code up or issues documenting cleanup.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the compiler team, which will review and decide on the PR/issue.