Skip to content

refactor the AssociatedItem structures #40697

Open
@nikomatsakis

Description

@nikomatsakis

During the work on #40668, there was some discussion about refactoring the ty::AssociatedItem and hir::{Impl,Trait}ItemRef data structures. The precise plan is a bit unclear, so I'm opening this issue to try and discuss and lay it out.

Observations:

  • Although ty::AssociatedItem lives in ty, it has no real dependencies and is based entirely on the HIR, so it would better live in HIR.
    • The existing ImplItemRef and TraitItemRef are basically specialized variants of AssociatedItem, though they add a Span and use local-ids (ImplItemId) rather than a DefId.
  • There is a need for a query that given a DefId gives you back the AssociatedItem (including across crates). The local-crate portion of this query seems like it could live in hir::map quite nicely.
  • Some of this setup is carefully crafted to avoid incorrect incremental dependencies and can change as we progress on the proposed red/green changes (in particular, the current query goes to some lengths to avoid reading from Hir(X) when computing AssociatedItem(X), instead reading from the containing impl/trait; this is because we don't want to require everything that needed even basic information about X to have to change when X changes).

cc @eddyb @cramertj

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions