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.

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
@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
@WaffleLapkin
Copy link
Copy Markdown
Member

r? fmease

@rustbot rustbot assigned fmease and unassigned WaffleLapkin May 1, 2026
@josetorrs josetorrs requested a review from fmease May 3, 2026 16:09
Copy link
Copy Markdown
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Sorry for the delay! Could you apply my suggestions, update PR title and the PR description which seem to be outdated and squash all commits into one? Thanks!

View changes since this review

Comment on lines +1404 to 1407
let def_id = alias_term.def_id;
let alias_kind = ty::AliasTyKind::new_from_def_id(tcx, def_id);
let alias_ty = ty::AliasTy::new_from_args(tcx, alias_kind, alias_term.args);
let ty = Ty::new_alias(tcx, alias_ty);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let def_id = alias_term.def_id;
let alias_kind = ty::AliasTyKind::new_from_def_id(tcx, def_id);
let alias_ty = ty::AliasTy::new_from_args(tcx, alias_kind, alias_term.args);
let ty = Ty::new_alias(tcx, alias_ty);
let ty = alias_term.expect_ty(tcx).to_ty(tcx);

Comment on lines +1442 to +1445
let def_id = alias_term.def_id;
self.require_type_const_attribute(def_id, span)?;
let ct = Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, args));
let ct =
Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, alias_term.args));
Copy link
Copy Markdown
Member

@fmease fmease May 7, 2026

Choose a reason for hiding this comment

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

Suggested change
let def_id = alias_term.def_id;
self.require_type_const_attribute(def_id, span)?;
let ct = Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, args));
let ct =
Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, alias_term.args));
self.require_type_const_attribute(alias_term.def_id, span)?;
let ct = Const::new_unevaluated(tcx, alias_term.expect_ct(tcx));


// FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
if let Some((did, args)) = self.probe_inherent_assoc_item(
if let Some((def_id, args)) = self.probe_inherent_assoc_item(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you make probe_inherent_assoc_item return an AliasTerm? So return a Result<Option<ty::AliasTerm<'tcx>>, ErrorGuaranteed>?

Additionally you could make lower_assoc_item_path return an AliasTerm directly to mirror the inherent counterpart but it's probably not worth it.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants