Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub enum PermitVariants {

#[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

edit: now (AliasTermKind, GenericArgsRef)

Copy link
Copy Markdown
Contributor Author

@josetorrs josetorrs May 1, 2026

Choose a reason for hiding this comment

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

@fmease I think this PR is outdated as #155392 added a DefId for AliasTermKind now so the option, (AliasTermKind, GenericArgsRef), should be viable now

meaning i'm closing this one but want to let you know

Variant { adt: Ty<'tcx>, variant_did: DefId },
Ctor { ctor_def_id: DefId, args: GenericArgsRef<'tcx> },
}
Expand Down Expand Up @@ -1400,12 +1400,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span,
LowerTypeRelativePathMode::Type(permit_variants),
)? {
TypeRelativePath::AssocItem(def_id, args) => {
let alias_ty = ty::AliasTy::new_from_args(
tcx,
ty::AliasTyKind::new_from_def_id(tcx, def_id),
args,
);
TypeRelativePath::AssocItem(alias_kind, args) => {
let def_id = alias_kind.def_id();
let alias_ty = ty::AliasTy::new_from_args(tcx, alias_kind, args);
let ty = Ty::new_alias(tcx, alias_ty);
let ty = self.check_param_uses_if_mcg(ty, span, false);
Ok((ty, tcx.def_kind(def_id), def_id))
Expand Down Expand Up @@ -1440,7 +1437,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span,
LowerTypeRelativePathMode::Const,
)? {
TypeRelativePath::AssocItem(def_id, args) => {
TypeRelativePath::AssocItem(alias_kind, args) => {
let def_id = alias_kind.def_id();
self.require_type_const_attribute(def_id, span)?;
let ct = Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, args));
let ct = self.check_param_uses_if_mcg(ct, span, false);
Expand Down Expand Up @@ -1572,15 +1570,15 @@ impl<'tcx> dyn HirTyLowerer<'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(
segment,
adt_def.did(),
self_ty,
qpath_hir_id,
span,
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

}
}

Expand Down Expand Up @@ -1614,7 +1612,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
);
}

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

}

/// Resolve a [type-relative](hir::QPath::TypeRelative) (and type-level) path.
Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.adt_def(adt_def_id)
}

fn alias_ty_kind_from_def_id(self, def_id: DefId) -> ty::AliasTyKind<'tcx> {
match self.def_kind(def_id) {
DefKind::AssocTy
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) =>
{
ty::Inherent { def_id }
}
DefKind::AssocTy => ty::Projection { def_id },

DefKind::OpaqueTy => ty::Opaque { def_id },
DefKind::TyAlias => ty::Free { def_id },
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
}
}

fn alias_term_kind(self, alias: ty::AliasTerm<'tcx>) -> ty::AliasTermKind {
match self.def_kind(alias.def_id) {
DefKind::AssocTy => {
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ pub trait Interner:
type AdtDef: AdtDef<Self>;
fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;

fn alias_ty_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTyKind<Self>;

fn alias_term_kind(self, alias: ty::AliasTerm<Self>) -> ty::AliasTermKind;

fn trait_ref_and_own_args_for_alias(
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_type_ir/src/ty_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ pub enum AliasTyKind<I: Interner> {
}

impl<I: Interner> AliasTyKind<I> {
pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self {
interner.alias_ty_kind_from_def_id(def_id)
}

pub fn descr(self) -> &'static str {
match self {
AliasTyKind::Projection { .. } => "associated type",
Expand Down
14 changes: 8 additions & 6 deletions src/tools/clippy/clippy_utils/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::traits::EvaluationResult;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind};
use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::{
self, AdtDef, AliasTy, AssocItem, AssocTag, Binder, BoundRegion, BoundVarIndexKind, FnSig, GenericArg,
self, AdtDef, AliasTy, AssocContainer, AssocItem, AssocTag, Binder, BoundRegion, BoundVarIndexKind, FnSig, GenericArg,
GenericArgKind, GenericArgsRef, IntTy, Region, RegionKind, TraitRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
TypeVisitableExt, TypeVisitor, UintTy, Upcast, VariantDef, VariantDiscr,
};
Expand Down Expand Up @@ -1023,11 +1023,13 @@ pub fn make_projection<'tcx>(
#[cfg(debug_assertions)]
assert_generic_args_match(tcx, assoc_item.def_id, args);

Some(AliasTy::new_from_args(
tcx,
ty::AliasTyKind::new_from_def_id(tcx, assoc_item.def_id),
args,
))
let alias_kind = match assoc_item.container {
AssocContainer::Trait | AssocContainer::TraitImpl(_) => {
ty::Projection { def_id: assoc_item.def_id }
}
AssocContainer::InherentImpl => ty::Inherent { def_id: assoc_item.def_id },
};
Some(AliasTy::new_from_args(tcx, alias_kind, args))
}
helper(
tcx,
Expand Down
Loading