Skip to content

Deduplication: Extract a shared helper function to remove duplicate associated const binding lowering#155196

Open
LaneAsade wants to merge 1 commit intorust-lang:mainfrom
LaneAsade:associated_const_binding_rhs_lowering
Open

Deduplication: Extract a shared helper function to remove duplicate associated const binding lowering#155196
LaneAsade wants to merge 1 commit intorust-lang:mainfrom
LaneAsade:associated_const_binding_rhs_lowering

Conversation

@LaneAsade
Copy link
Copy Markdown
Contributor

@LaneAsade LaneAsade commented Apr 12, 2026

This PR aims to deduplicate the code the responsible for lowering the RHS of associated const bindings (found at bounds.rs and mod.rs) by creating a helper function lower_assoc_const_binding_rhs.

Related: #150621

Helper function code:

pub(crate) fn lower_assoc_const_binding_rhs(
        &self,
        ct: &'tcx hir::ConstArg<'tcx>,
        assoc_ident: Ident,
        constraint_hir_id: hir::HirId,
        projection_term: ty::Binder<'tcx, ty::AliasTerm<'tcx>>,
    ) -> ty::Const<'tcx> {
        let tcx = self.tcx();
        let ty = projection_term
            .map_bound(|alias| tcx.type_of(alias.def_id).instantiate(tcx, alias.args));
        let ty = check_assoc_const_binding_type(self, assoc_ident, ty, constraint_hir_id);
        self.lower_const_arg(ct, ty)
}

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 69 candidates
  • Random selection from 12 candidates

@afurm
Copy link
Copy Markdown

afurm commented Apr 12, 2026

Nit: check_assoc_const_binding_type is called as bounds::check_assoc_const_binding_type at the mod.rs call site but as just check_assoc_const_binding_type (direct) at the bounds.rs call site — the helper normalises this to always call it as a method on self, which is correct, but worth verifying the two sites were always semantically equivalent (the FIXME comment in the old mod.rs code hints this was previously uncertain).

@LaneAsade
Copy link
Copy Markdown
Contributor Author

As far as I know, the FIXME in the old mod.rs was about code duplication in lowering the RHS type and not about the equivalence of the two call sites. Even then, the two call sites are semantically equivalent so no worries there. Thank you for the feedback though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants