Skip to content

removing new_from_def_id and alias_ty_kind_from_def_id methods, small refactor to TypeRelativePath::AssocItem#155323

Open
josetorrs wants to merge 2 commits intorust-lang:mainfrom
josetorrs:remove-new-from-def-id
Open

removing new_from_def_id and alias_ty_kind_from_def_id methods, small refactor to TypeRelativePath::AssocItem#155323
josetorrs wants to merge 2 commits intorust-lang:mainfrom
josetorrs:remove-new-from-def-id

Conversation

@josetorrs
Copy link
Copy Markdown
Contributor

@josetorrs josetorrs commented Apr 15, 2026

r? @WaffleLapkin

related issue: #154941

tackling the task:

  • remove calls to new_from_def_id and alias_ty_kind_from_def_id and replace them with calls to e.g. new_projection directly

in probe_inherent_assoc_item only searches inherent impls here, so the result is always Inherent. in resolve_type_relative_path the result is always Projection.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 15, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 15, 2026

WaffleLapkin is not on the review rotation at the moment.
They may take a while to respond.

#[derive(Debug, Clone, Copy)]
enum TypeRelativePath<'tcx> {
AssocItem(DefId, GenericArgsRef<'tcx>),
AssocItem(ty::AliasTyKind<'tcx>, GenericArgsRef<'tcx>),
Copy link
Copy Markdown
Member

@fmease fmease Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is misleading, AssocItem can represent associated constants under mGCA.

You can see yourself how in lower_type_relative_const_path you merely extract the DefId and ignore the actual kind.

Conceptually this (DefId, GenericArgRef) is an AliasTerm.

If anything, the entire payload should either be changed to AliasTerm or to (AliasTermKind, GenericArgsRef) if we don't want to intern it too early or it should just remain as is if the other options end up disimproving the lowering code.

View changes since the review

Copy link
Copy Markdown
Contributor Author

@josetorrs josetorrs Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think the AliasTerm change makes sense.

this may be a dumb question but when you mention the other option: (AliasTermKind, GenericArgsRef). I looked at it here and it doesn't seem to have a DefId though it appears to be the long term goal based on the last task in the linked issue:

remove def_id param of opt_alias_variances after AliasTermKind contains def_id within

did you mean (AliasTermKind, DefId, GenericArgsRef)?

Copy link
Copy Markdown
Member

@fmease fmease Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not a dumb question at all! I'm only loosely following #154941, so I didn't realize that AliasTermKind wasn't updated yet and just assumed it was.

Right, (AliasTermKind, DefId, GenericArgsRef) would be an option or we wait until AliasTermKind has a DefId. I don't want to call the shots here though since WaffleLapkin guides this initiative.

I'm just the self-proclaimed janitor of HIR ty lowering :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to AliasTerm here: dc59a2a

though now that I'm looking at it, it's still using the methods new_from_def_id and alias_ty_kind_from_def_id

Copy link
Copy Markdown
Contributor Author

@josetorrs josetorrs Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i raised #155371 as an alternative for the (AliasTermKind, DefId, GenericArgsRef) option. lmk what you think

mode.assoc_tag(),
)? {
return Ok(TypeRelativePath::AssocItem(did, args));
return Ok(TypeRelativePath::AssocItem(ty::Inherent { def_id }, args));
Copy link
Copy Markdown
Member

@fmease fmease Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, def_id can just as well refer to a type-level inherent associated constant.

View changes since the review

}

Ok(TypeRelativePath::AssocItem(item_def_id, args))
Ok(TypeRelativePath::AssocItem(ty::Projection { def_id: item_def_id }, args))
Copy link
Copy Markdown
Member

@fmease fmease Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, item_def_id can just as well refer to a type-level associated constant.

View changes since the review

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 15, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@josetorrs josetorrs marked this pull request as ready for review April 16, 2026 01:31
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 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. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 16, 2026
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-clippy Relevant to the Clippy team. 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