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>),
Comment thread
fmease marked this conversation as resolved.
Outdated
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);
Comment on lines +1404 to 1407
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);

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(
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.

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));
Comment thread
fmease marked this conversation as resolved.
Outdated
}
}

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))
Comment thread
fmease marked this conversation as resolved.
Outdated
}

/// 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