From caedbd84f292c4c4ab129607b0ddfc10c1aa5e99 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Thu, 17 Sep 2026 06:52:28 +0200 Subject: [PATCH] yeet alias new_from_def_id --- .../src/hir_ty_lowering/bounds.rs | 12 ++-- .../src/hir_ty_lowering/errors.rs | 10 ++- .../src/hir_ty_lowering/mod.rs | 32 ++++----- compiler/rustc_middle/src/mir/consts.rs | 25 ++++--- .../src/ty/context/impl_interner.rs | 65 ------------------- .../src/builder/expr/as_constant.rs | 30 +++++---- compiler/rustc_mir_build/src/thir/cx/expr.rs | 4 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 33 ++++------ .../cfi/typeid/itanium_cxx_abi/transform.rs | 25 ++++--- compiler/rustc_ty_utils/src/consts.rs | 27 ++++---- compiler/rustc_type_ir/src/const_kind.rs | 13 ---- compiler/rustc_type_ir/src/interner.rs | 17 +---- compiler/rustc_type_ir/src/predicate.rs | 16 +++-- compiler/rustc_type_ir/src/relate.rs | 11 +--- compiler/rustc_type_ir/src/term_kind.rs | 10 --- 15 files changed, 115 insertions(+), 215 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 8b0da8c28d1e1..7f0c6910cc425 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -476,12 +476,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); debug!(?alias_args); - ty::AliasTerm::new_from_def_id( - tcx, - assoc_item.def_id, - alias_args, - ty::AliasConstInherentArgsKind::WithSelf, - ) + let kind = if let ty::AssocTag::Const = assoc_tag { + ty::AliasTermKind::ProjectionConst { def_id: assoc_item.def_id } + } else { + ty::AliasTermKind::ProjectionTy { def_id: assoc_item.def_id } + }; + ty::AliasTerm::new_from_args(tcx, kind, alias_args) }) }; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index 59ce0cded29e4..2a3728573f31e 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -480,12 +480,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &item_segment, trait_ref.args, ); - ty::AliasTerm::new_from_def_id( - tcx, - assoc_item.def_id, - alias_args, - ty::AliasConstInherentArgsKind::WithSelf, - ) + let kind = ty::AliasTermKind::ProjectionConst { + def_id: assoc_item.def_id, + }; + ty::AliasTerm::new_from_args(tcx, kind, alias_args) }); // FIXME(mgca): code duplication with other places we lower diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index b659dd896aba0..81ef0d3890d42 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1608,12 +1608,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); } - Ok(TypeRelativePath::AssocItem(ty::AliasTerm::new_from_def_id( - tcx, - item_def_id, - args, - ty::AliasConstInherentArgsKind::WithSelf, - ))) + let kind = match mode { + LowerTypeRelativePathMode::Type(..) => { + ty::AliasTermKind::ProjectionTy { def_id: item_def_id } + } + LowerTypeRelativePathMode::Const => { + ty::AliasTermKind::ProjectionConst { def_id: item_def_id } + } + }; + + Ok(TypeRelativePath::AssocItem(ty::AliasTerm::new_from_args(tcx, kind, args))) } /// Resolve a [type-relative](hir::QPath::TypeRelative) (and type-level) path. @@ -1947,11 +1951,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { self.check_const_item_in_type_system(item_def_id, span)?; let alias_const = ty::AliasConst::new( tcx, - ty::AliasConstKind::new_from_def_id( - tcx, - item_def_id, - ty::AliasConstInherentArgsKind::WithSelf, - ), + ty::AliasConstKind::Projection { def_id: item_def_id }, item_args, ); Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const)) @@ -2911,15 +2911,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ty::Const::new_alias( tcx, ty::IsRigid::No, - ty::AliasConst::new( - tcx, - ty::AliasConstKind::new_from_def_id( - tcx, - did, - ty::AliasConstInherentArgsKind::WithSelf, - ), - args, - ), + ty::AliasConst::new(tcx, ty::AliasConstKind::Free { def_id: did }, args), ) } Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => { diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 9b12bd144a111..83f62ee65025c 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -1,6 +1,7 @@ use std::fmt::{self, Debug, Display, Formatter}; use rustc_abi::{HasDataLayout, Size}; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_macros::{Lift, StableHash, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_span::{DUMMY_SP, RemapPathScopeComponents, Span, Symbol, bug}; @@ -478,15 +479,21 @@ impl<'tcx> UnevaluatedConst<'tcx> { #[inline] pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::AliasConst<'tcx> { assert_eq!(self.promoted, None); - ty::AliasConst::new( - tcx, - ty::AliasConstKind::new_from_def_id( - tcx, - self.def, - ty::AliasConstInherentArgsKind::Impl, - ), - self.args, - ) + + let kind = match tcx.def_kind(self.def) { + DefKind::AssocConst => { + if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def)) { + ty::AliasConstKind::InherentImpl { def_id: self.def } + } else { + ty::AliasConstKind::Projection { def_id: self.def } + } + } + DefKind::Const => ty::AliasConstKind::Free { def_id: self.def }, + DefKind::AnonConst => ty::AliasConstKind::Anon { def_id: self.def }, + kind => bug!("unexpected DefKind in MIR UnevaluatedConst: {kind:?}"), + }; + + ty::AliasConst::new(tcx, kind, self.args) } } diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 0cb926ec1c108..50e823f88178f 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -220,71 +220,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.adt_def(adt_def_id) } - fn alias_const_kind_from_def_id( - self, - def_id: Self::DefId, - inherent_args: ty::AliasConstInherentArgsKind, - ) -> ty::AliasConstKind<'tcx> { - match self.def_kind(def_id) { - DefKind::AssocConst => { - if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { - match inherent_args { - ty::AliasConstInherentArgsKind::WithSelf => { - ty::AliasConstKind::InherentSelf { def_id } - } - ty::AliasConstInherentArgsKind::Impl => { - ty::AliasConstKind::InherentImpl { def_id } - } - } - } else { - ty::AliasConstKind::Projection { def_id } - } - } - DefKind::Const => ty::AliasConstKind::Free { def_id }, - DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => { - ty::AliasConstKind::Anon { def_id } - } - kind => bug!("unexpected DefKind in AliasConst: {kind:?}"), - } - } - - fn alias_term_kind_from_def_id( - self, - def_id: DefId, - inherent_args: ty::AliasConstInherentArgsKind, - ) -> ty::AliasTermKind<'tcx> { - match self.def_kind(def_id) { - DefKind::AssocTy => { - if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { - ty::AliasTermKind::InherentTy { def_id } - } else { - ty::AliasTermKind::ProjectionTy { def_id } - } - } - DefKind::AssocConst => { - if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { - match inherent_args { - ty::AliasConstInherentArgsKind::WithSelf => { - ty::AliasTermKind::InherentConstSelf { def_id } - } - ty::AliasConstInherentArgsKind::Impl => { - ty::AliasTermKind::InherentConstImpl { def_id } - } - } - } else { - ty::AliasTermKind::ProjectionConst { def_id } - } - } - DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy { def_id }, - DefKind::TyAlias => ty::AliasTermKind::FreeTy { def_id }, - DefKind::Const => ty::AliasTermKind::FreeConst { def_id }, - DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => { - ty::AliasTermKind::AnonConst { def_id } - } - kind => bug!("unexpected DefKind in AliasTy: {kind:?}"), - } - } - fn trait_ref_and_own_args_for_alias( self, def_id: DefId, diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs index 6d48831a3d23b..eb9f56d887684 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs @@ -73,33 +73,37 @@ pub(crate) fn as_constant_inner<'tcx>( } ExprKind::NamedConst { def_id, args, ref user_ty } => { let user_ty = user_ty.as_ref().and_then(push_cuta); + // Under generic_const_args, `def_id` might be a regular const declared in a trait, but // is `impl`d as a directly represented const. We do not know whether it is here, so we // must use type system normalization for all consts under generic_const_args. // FIXME(generic_const_args): there's a lot to consider here! `Const::Ty` uses valtrees // and `Const::Unevaluated` does not, we should revisit this before stabilization. + let def_kind = tcx.def_kind(def_id); if tcx.features().generic_const_args() - || matches!(tcx.def_kind(def_id), DefKind::Const | DefKind::AssocConst) + || matches!(def_kind, DefKind::Const | DefKind::AssocConst) && tcx.is_direct_const(def_id) { - let uneval = ty::AliasConst::new( - tcx, - ty::AliasConstKind::new_from_def_id( - tcx, - def_id, - ty::AliasConstInherentArgsKind::Impl, - ), - args, - ); - let ct = ty::Const::new_alias(tcx, ty::IsRigid::No, uneval); - + let kind = match def_kind { + DefKind::AssocConst => { + if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(def_id)) + { + ty::AliasConstKind::InherentImpl { def_id } + } else { + ty::AliasConstKind::Projection { def_id } + } + } + DefKind::Const => ty::AliasConstKind::Free { def_id }, + _ => unreachable!(), + }; + let alias = ty::AliasConst::new(tcx, kind, args); + let ct = ty::Const::new_alias(tcx, ty::IsRigid::No, alias); let const_ = Const::Ty(ty, ct); return ConstOperand { span, user_ty, const_ }; } let uneval = mir::UnevaluatedConst::new(def_id, args); let const_ = Const::Unevaluated(uneval, ty); - ConstOperand { user_ty, span, const_ } } ExprKind::ConstParam { param, def_id: _ } => { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index c2d1739d37187..feef8d24bd9ca 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -327,7 +327,7 @@ impl<'tcx> ThirBuildCx<'tcx> { } else if let hir::ExprKind::Path(ref qpath) = source.kind && let res = self.typeck_results.qpath_res(qpath, source.hir_id) && let ty = self.typeck_results.node_type(source.hir_id) - && let ty::Adt(adt_def, args) = ty.kind() + && let ty::Adt(adt_def, _) = ty.kind() && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res { // Check whether this is casting an enum variant discriminant. @@ -369,6 +369,8 @@ impl<'tcx> ThirBuildCx<'tcx> { // in case we are offsetting from a computed discriminant // and not the beginning of discriminants (which is always `0`) Some(did) => { + let args = self.tcx.mk_args(&[]); + self.tcx.debug_assert_args_compatible(did, args); let kind = ExprKind::NamedConst { def_id: did, args, user_ty: None }; let lhs = self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind }); diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index ff3f643303972..5b7a4d626aae3 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -635,9 +635,17 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { let ty = self.typeck_results.node_type(id); let res = self.typeck_results.qpath_res(qpath, id); - let (def_id, user_ty) = match res { - Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { - (def_id, self.typeck_results.user_provided_types().get(id)) + let kind = match res { + Res::Def(DefKind::Const, def_id) => ty::AliasConstKind::Free { def_id }, + + Res::Def(DefKind::AssocConst, def_id) => { + if let DefKind::Impl { of_trait: false } = + self.tcx.def_kind(self.tcx.parent(def_id)) + { + ty::AliasConstKind::InherentImpl { def_id } + } else { + ty::AliasConstKind::Projection { def_id } + } } _ => { @@ -649,26 +657,13 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { // Lower the named constant to a THIR pattern. let args = self.typeck_results.node_args(id); - // FIXME(mgca): we will need to special case IACs here to have type system compatible - // generic args, instead of how we represent them in body expressions. - let c = ty::Const::new_alias( - self.tcx, - ty::IsRigid::No, - ty::AliasConst::new( - self.tcx, - ty::AliasConstKind::new_from_def_id( - self.tcx, - def_id, - ty::AliasConstInherentArgsKind::Impl, - ), - args, - ), - ); + let alias = ty::AliasConst::new(self.tcx, kind, args); + let c = ty::Const::new_alias(self.tcx, ty::IsRigid::No, alias); let mut pattern = self.const_to_pat(c, ty, id, span); // If this is an associated constant with an explicit user-written // type, add an ascription node (e.g. ` as MyTrait>::CONST`). - if let Some(&user_ty) = user_ty { + if let Some(&user_ty) = self.typeck_results.user_provided_types().get(id) { let annotation = CanonicalUserTypeAnnotation { user_ty: Box::new(user_ty), span, diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index 2b42d1fdf79bb..017e35056f45b 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -245,24 +245,23 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc .filter(|item| !tcx.generics_require_sized_self(item.def_id)) .map(move |assoc_item| { super_poly_trait_ref.map_bound(|super_trait_ref| { - let projection_term = ty::AliasTerm::new_from_def_id( - tcx, - assoc_item.def_id, - super_trait_ref.args, - ty::AliasConstInherentArgsKind::WithSelf, - ); - let term = tcx.normalize_erasing_regions( + let kind = if assoc_item.is_type() { + ty::AliasTermKind::ProjectionTy { def_id: assoc_item.def_id } + } else { + ty::AliasTermKind::ProjectionConst { def_id: assoc_item.def_id } + }; + let projection_term = + ty::AliasTerm::new_from_args(tcx, kind, super_trait_ref.args); + let term = projection_term.to_term(tcx, ty::IsRigid::No); + let normalized_term = tcx.normalize_erasing_regions( ty::TypingEnv::fully_monomorphized(), - Unnormalized::new_wip(projection_term.to_term(tcx, ty::IsRigid::No)), - ); - debug!( - "Projection {:?} -> {term}", - projection_term.to_term(tcx, ty::IsRigid::No) + Unnormalized::new_wip(term), ); + debug!("Projection {term} -> {normalized_term}"); ty::ExistentialPredicate::Projection( ty::ExistentialProjection::erase_self_ty( tcx, - ty::ProjectionClause { projection_term, term }, + ty::ProjectionClause { projection_term, term: normalized_term }, ), ) }) diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 6db234fd886ca..0507265ded631 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -7,7 +7,7 @@ use rustc_middle::thir::visit::Visitor; use rustc_middle::ty::abstract_const::CastKind; use rustc_middle::ty::{self, Expr, LitToConstInput, TyCtxt, TypeVisitableExt}; use rustc_middle::{mir, thir}; -use rustc_span::Span; +use rustc_span::{Span, bug}; use tracing::instrument; use crate::diagnostics::{GenericConstantTooComplex, GenericConstantTooComplexSub}; @@ -70,16 +70,21 @@ fn recurse_build<'tcx>( } &ExprKind::ZstLiteral { user_ty: _ } => ty::Const::zero_sized(tcx, node.ty), &ExprKind::NamedConst { def_id, args, user_ty: _ } => { - let uneval = ty::AliasConst::new( - tcx, - ty::AliasConstKind::new_from_def_id( - tcx, - def_id, - ty::AliasConstInherentArgsKind::Impl, - ), - args, - ); - ty::Const::new_alias(tcx, ty::IsRigid::No, uneval) + let kind = match tcx.def_kind(def_id) { + DefKind::AssocConst => { + if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(def_id)) { + ty::AliasConstKind::InherentImpl { def_id } + } else { + ty::AliasConstKind::Projection { def_id } + } + } + DefKind::Const => ty::AliasConstKind::Free { def_id }, + DefKind::AnonConst => ty::AliasConstKind::Anon { def_id }, + kind => bug!("unexpected DefKind in THIR ExprKind::NamedConst: {kind:?}"), + }; + + let alias = ty::AliasConst::new(tcx, kind, args); + ty::Const::new_alias(tcx, ty::IsRigid::No, alias) } ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param), diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 36cef1c13eb29..dd0578610a2a0 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -146,20 +146,7 @@ pub enum AliasConstKind { Anon { def_id: I::AnonConstId }, } -pub enum AliasConstInherentArgsKind { - WithSelf, - Impl, -} - impl AliasConstKind { - pub fn new_from_def_id( - interner: I, - def_id: I::DefId, - inherent_args: AliasConstInherentArgsKind, - ) -> Self { - interner.alias_const_kind_from_def_id(def_id, inherent_args) - } - pub fn is_direct_const(self, interner: I) -> bool { interner.is_direct_const(self) } diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 31a027c15fd01..289f5dc2e1b46 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -86,10 +86,10 @@ pub trait Interner: type AnonConstId: SpecificDefId; type TraitAssocTyId: SpecificDefId + Into - + TryFrom; + + TryFrom; type TraitAssocConstId: SpecificDefId + Into - + TryFrom; + + TryFrom; type TraitAssocTermId: SpecificDefId; type OpaqueTyId: SpecificDefId; type LocalOpaqueTyId: Copy @@ -293,19 +293,6 @@ pub trait Interner: type AdtDef: AdtDef; fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef; - fn alias_const_kind_from_def_id( - self, - def_id: Self::DefId, - inherent_args: ty::AliasConstInherentArgsKind, - ) -> ty::AliasConstKind; - - // FIXME: remove in favor of explicit construction - fn alias_term_kind_from_def_id( - self, - def_id: Self::DefId, - inherent_args: ty::AliasConstInherentArgsKind, - ) -> ty::AliasTermKind; - fn trait_ref_and_own_args_for_alias( self, def_id: Self::TraitAssocTermId, diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 7ad23d3e5432a..e66ef5fe99b4a 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -495,6 +495,17 @@ impl ExistentialProjection { ExistentialTraitRef::new_from_args(interner, def_id, args) } + pub fn alias_kind(&self) -> ty::AliasTermKind { + match self.term.kind() { + ty::TermKind::Ty(_) => { + ty::AliasTermKind::ProjectionTy { def_id: self.def_id.try_into().unwrap() } + } + ty::TermKind::Const(_) => { + ty::AliasTermKind::ProjectionConst { def_id: self.def_id.try_into().unwrap() } + } + } + } + pub fn with_self_ty(&self, interner: I, self_ty: I::Ty) -> ProjectionClause { // otherwise the escaping regions would be captured by the binders debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -502,10 +513,7 @@ impl ExistentialProjection { ProjectionClause { projection_term: ty::AliasTerm::new( interner, - interner.alias_term_kind_from_def_id( - self.def_id.into(), - ty::AliasConstInherentArgsKind::WithSelf, - ), + self.alias_kind(), [self_ty.into()].iter().chain(self.args.iter()), ), term: self.term, diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index f6491bac642e3..49fcb38968abe 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -281,16 +281,7 @@ impl Relate for ty::ExistentialProjection { b: ty::ExistentialProjection, ) -> RelateResult> { if a.def_id != b.def_id { - Err(TypeError::ProjectionMismatched(ExpectedFound::new( - relation.cx().alias_term_kind_from_def_id( - a.def_id.into(), - ty::AliasConstInherentArgsKind::WithSelf, - ), - relation.cx().alias_term_kind_from_def_id( - b.def_id.into(), - ty::AliasConstInherentArgsKind::WithSelf, - ), - ))) + Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.alias_kind(), b.alias_kind()))) } else { let term = relation.relate_with_variance( ty::Invariant, diff --git a/compiler/rustc_type_ir/src/term_kind.rs b/compiler/rustc_type_ir/src/term_kind.rs index ed23b196fe269..6a4b1f023dde2 100644 --- a/compiler/rustc_type_ir/src/term_kind.rs +++ b/compiler/rustc_type_ir/src/term_kind.rs @@ -169,16 +169,6 @@ impl AliasTerm { Self::new_from_args(interner, kind, args) } - pub fn new_from_def_id( - interner: I, - def_id: I::DefId, - args: I::GenericArgs, - inherent_args: ty::AliasConstInherentArgsKind, - ) -> AliasTerm { - let kind = interner.alias_term_kind_from_def_id(def_id, inherent_args); - Self::new_from_args(interner, kind, args) - } - pub fn expect_ty(self) -> ty::AliasTy { let kind = match self.kind { AliasTermKind::ProjectionTy { def_id } => ty::AliasTyKind::Projection { def_id },