Skip to content

Simplify universal impl-trait collection during lowering #96644

Closed
@cjgillot

Description

@cjgillot

During lowering (rustc_ast_lowering), universal impl-trait are desugared to extra generic parameters to the current item, and their bounds added to the where clause.

fn foo<T>(u: impl Bar) where T: Foo

becomes

fn foo<T, _U>(u: _U) where T: Foo, _U: Bar

This is done by carrying two vectors inside ImplTraitContext::Universal.
These vectors are only created by add_implicit_generics method, and references to them are passed around.
We should prefer having them as fields in LoweringContext.

Instructions:

  • Move the two vectors from ImplTraitContext::Universal to field in LoweringContext;
  • Take and replace the values of these fields in with_hir_id_owner, and assert that the value after the call to f is empty;
  • Add a itctx: ImplTraitContext parameter to add_implicit_generics and assert that these fields are empty on return if itctxt is not Universal;
  • Replace all calls to lower_generics by calls to add_implicit_generics;
  • Rename add_implicit_generics to lower_generics;
  • Maybe inline lower_generics_mut into lower_generics (if this simplifies the logic, not sure).

Please contact me on zulip for any question.

Metadata

Metadata

Assignees

Labels

A-HIRArea: The high-level intermediate representation (HIR)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions