From 19664e276aba21a42cad5351a2c91995d1ce5d52 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 13 Mar 2021 17:36:07 +0100 Subject: Use chalk_ir::AssocTypeId --- crates/hir_ty/src/traits/chalk/mapping.rs | 47 +++++++++---------------------- crates/hir_ty/src/traits/chalk/tls.rs | 9 +++--- 2 files changed, 18 insertions(+), 38 deletions(-) (limited to 'crates/hir_ty/src/traits/chalk') diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index cf490f9c5..67ac95a0e 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -14,6 +14,7 @@ use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId}; use crate::{ db::HirDatabase, + from_assoc_type_id, primitive::UintTy, traits::{Canonical, Obligation}, AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, @@ -38,9 +39,7 @@ impl ToChalk for Ty { }) .intern(&Interner) } - TyKind::AssociatedType(type_alias, substs) => { - let assoc_type = TypeAliasAsAssocType(type_alias); - let assoc_type_id = assoc_type.to_chalk(db); + TyKind::AssociatedType(assoc_type_id, substs) => { let substitution = substs.to_chalk(db); chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) } @@ -85,7 +84,7 @@ impl ToChalk for Ty { chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) } TyKind::Alias(AliasTy::Projection(proj_ty)) => { - let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); + let associated_ty_id = proj_ty.associated_ty; let substitution = proj_ty.parameters.to_chalk(db); chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { associated_ty_id, @@ -139,8 +138,7 @@ impl ToChalk for Ty { TyKind::Placeholder(db.lookup_intern_type_param_id(interned_id)) } chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { - let associated_ty = - from_chalk::(db, proj.associated_ty_id).0; + let associated_ty = proj.associated_ty_id; let parameters = from_chalk(db, proj.substitution); TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) } @@ -180,10 +178,9 @@ impl ToChalk for Ty { } chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)), - chalk_ir::TyKind::AssociatedType(type_id, subst) => TyKind::AssociatedType( - from_chalk::(db, type_id).0, - from_chalk(db, subst), - ), + chalk_ir::TyKind::AssociatedType(type_id, subst) => { + TyKind::AssociatedType(type_id, from_chalk(db, subst)) + } chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) @@ -332,20 +329,6 @@ impl ToChalk for CallableDefId { } } -pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId); - -impl ToChalk for TypeAliasAsAssocType { - type Chalk = AssocTypeId; - - fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { - chalk_ir::AssocTypeId(self.0.as_intern_id()) - } - - fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType { - TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0)) - } -} - pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); impl ToChalk for TypeAliasAsValue { @@ -427,7 +410,7 @@ impl ToChalk for ProjectionTy { fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy { chalk_ir::ProjectionTy { - associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), + associated_ty_id: self.associated_ty, substitution: self.parameters.to_chalk(db), } } @@ -437,11 +420,7 @@ impl ToChalk for ProjectionTy { projection_ty: chalk_ir::ProjectionTy, ) -> ProjectionTy { ProjectionTy { - associated_ty: from_chalk::( - db, - projection_ty.associated_ty_id, - ) - .0, + associated_ty: projection_ty.associated_ty_id, parameters: from_chalk(db, projection_ty.substitution), } } @@ -595,7 +574,10 @@ pub(super) fn generic_predicate_to_inline_bound( if &proj.projection_ty.parameters[0] != self_ty { return None; } - let trait_ = match proj.projection_ty.associated_ty.lookup(db.upcast()).container { + let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty) + .lookup(db.upcast()) + .container + { AssocContainerId::TraitId(t) => t, _ => panic!("associated type not in trait"), }; @@ -606,8 +588,7 @@ pub(super) fn generic_predicate_to_inline_bound( let alias_eq_bound = rust_ir::AliasEqBound { value: proj.ty.clone().to_chalk(db), trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, - associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) - .to_chalk(db), + associated_ty_id: proj.projection_ty.associated_ty, parameters: Vec::new(), // FIXME we don't support generic associated types yet }; Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs index 75b16172e..8892a63a9 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/traits/chalk/tls.rs @@ -4,8 +4,8 @@ use std::fmt; use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; use itertools::Itertools; -use super::{from_chalk, Interner, TypeAliasAsAssocType}; -use crate::{db::HirDatabase, CallableDefId}; +use super::{from_chalk, Interner}; +use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId}; use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; pub(crate) use unsafe_tls::{set_current_program, with_current_program}; @@ -41,7 +41,7 @@ impl DebugContext<'_> { id: super::AssocTypeId, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let type_alias: TypeAliasId = from_chalk::(self.0, id).0; + let type_alias: TypeAliasId = from_assoc_type_id(id); let type_alias_data = self.0.type_alias_data(type_alias); let trait_ = match type_alias.lookup(self.0.upcast()).container { AssocContainerId::TraitId(t) => t, @@ -75,8 +75,7 @@ impl DebugContext<'_> { projection_ty: &chalk_ir::ProjectionTy, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let type_alias: TypeAliasId = - from_chalk::(self.0, projection_ty.associated_ty_id).0; + let type_alias = from_assoc_type_id(projection_ty.associated_ty_id); let type_alias_data = self.0.type_alias_data(type_alias); let trait_ = match type_alias.lookup(self.0.upcast()).container { AssocContainerId::TraitId(t) => t, -- cgit v1.2.3