aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-13 16:36:07 +0000
committerFlorian Diebold <[email protected]>2021-03-13 16:56:48 +0000
commit19664e276aba21a42cad5351a2c91995d1ce5d52 (patch)
tree34a0c9ed9c374605f59ab839a5c8193b440c7a2a /crates/hir_ty/src/traits/chalk
parentdfafcd926a4cc9b09aba0eb3cc5275a4abe633b9 (diff)
Use chalk_ir::AssocTypeId
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs47
-rw-r--r--crates/hir_ty/src/traits/chalk/tls.rs9
2 files changed, 18 insertions, 38 deletions
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};
14 14
15use crate::{ 15use crate::{
16 db::HirDatabase, 16 db::HirDatabase,
17 from_assoc_type_id,
17 primitive::UintTy, 18 primitive::UintTy,
18 traits::{Canonical, Obligation}, 19 traits::{Canonical, Obligation},
19 AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, 20 AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy,
@@ -38,9 +39,7 @@ impl ToChalk for Ty {
38 }) 39 })
39 .intern(&Interner) 40 .intern(&Interner)
40 } 41 }
41 TyKind::AssociatedType(type_alias, substs) => { 42 TyKind::AssociatedType(assoc_type_id, substs) => {
42 let assoc_type = TypeAliasAsAssocType(type_alias);
43 let assoc_type_id = assoc_type.to_chalk(db);
44 let substitution = substs.to_chalk(db); 43 let substitution = substs.to_chalk(db);
45 chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) 44 chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner)
46 } 45 }
@@ -85,7 +84,7 @@ impl ToChalk for Ty {
85 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) 84 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner)
86 } 85 }
87 TyKind::Alias(AliasTy::Projection(proj_ty)) => { 86 TyKind::Alias(AliasTy::Projection(proj_ty)) => {
88 let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); 87 let associated_ty_id = proj_ty.associated_ty;
89 let substitution = proj_ty.parameters.to_chalk(db); 88 let substitution = proj_ty.parameters.to_chalk(db);
90 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { 89 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
91 associated_ty_id, 90 associated_ty_id,
@@ -139,8 +138,7 @@ impl ToChalk for Ty {
139 TyKind::Placeholder(db.lookup_intern_type_param_id(interned_id)) 138 TyKind::Placeholder(db.lookup_intern_type_param_id(interned_id))
140 } 139 }
141 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { 140 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
142 let associated_ty = 141 let associated_ty = proj.associated_ty_id;
143 from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0;
144 let parameters = from_chalk(db, proj.substitution); 142 let parameters = from_chalk(db, proj.substitution);
145 TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) 143 TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters }))
146 } 144 }
@@ -180,10 +178,9 @@ impl ToChalk for Ty {
180 } 178 }
181 179
182 chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)), 180 chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)),
183 chalk_ir::TyKind::AssociatedType(type_id, subst) => TyKind::AssociatedType( 181 chalk_ir::TyKind::AssociatedType(type_id, subst) => {
184 from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0, 182 TyKind::AssociatedType(type_id, from_chalk(db, subst))
185 from_chalk(db, subst), 183 }
186 ),
187 184
188 chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { 185 chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => {
189 TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) 186 TyKind::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst))
@@ -332,20 +329,6 @@ impl ToChalk for CallableDefId {
332 } 329 }
333} 330}
334 331
335pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId);
336
337impl ToChalk for TypeAliasAsAssocType {
338 type Chalk = AssocTypeId;
339
340 fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId {
341 chalk_ir::AssocTypeId(self.0.as_intern_id())
342 }
343
344 fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType {
345 TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0))
346 }
347}
348
349pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); 332pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
350 333
351impl ToChalk for TypeAliasAsValue { 334impl ToChalk for TypeAliasAsValue {
@@ -427,7 +410,7 @@ impl ToChalk for ProjectionTy {
427 410
428 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { 411 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
429 chalk_ir::ProjectionTy { 412 chalk_ir::ProjectionTy {
430 associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), 413 associated_ty_id: self.associated_ty,
431 substitution: self.parameters.to_chalk(db), 414 substitution: self.parameters.to_chalk(db),
432 } 415 }
433 } 416 }
@@ -437,11 +420,7 @@ impl ToChalk for ProjectionTy {
437 projection_ty: chalk_ir::ProjectionTy<Interner>, 420 projection_ty: chalk_ir::ProjectionTy<Interner>,
438 ) -> ProjectionTy { 421 ) -> ProjectionTy {
439 ProjectionTy { 422 ProjectionTy {
440 associated_ty: from_chalk::<TypeAliasAsAssocType, _>( 423 associated_ty: projection_ty.associated_ty_id,
441 db,
442 projection_ty.associated_ty_id,
443 )
444 .0,
445 parameters: from_chalk(db, projection_ty.substitution), 424 parameters: from_chalk(db, projection_ty.substitution),
446 } 425 }
447 } 426 }
@@ -595,7 +574,10 @@ pub(super) fn generic_predicate_to_inline_bound(
595 if &proj.projection_ty.parameters[0] != self_ty { 574 if &proj.projection_ty.parameters[0] != self_ty {
596 return None; 575 return None;
597 } 576 }
598 let trait_ = match proj.projection_ty.associated_ty.lookup(db.upcast()).container { 577 let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty)
578 .lookup(db.upcast())
579 .container
580 {
599 AssocContainerId::TraitId(t) => t, 581 AssocContainerId::TraitId(t) => t,
600 _ => panic!("associated type not in trait"), 582 _ => panic!("associated type not in trait"),
601 }; 583 };
@@ -606,8 +588,7 @@ pub(super) fn generic_predicate_to_inline_bound(
606 let alias_eq_bound = rust_ir::AliasEqBound { 588 let alias_eq_bound = rust_ir::AliasEqBound {
607 value: proj.ty.clone().to_chalk(db), 589 value: proj.ty.clone().to_chalk(db),
608 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, 590 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
609 associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) 591 associated_ty_id: proj.projection_ty.associated_ty,
610 .to_chalk(db),
611 parameters: Vec::new(), // FIXME we don't support generic associated types yet 592 parameters: Vec::new(), // FIXME we don't support generic associated types yet
612 }; 593 };
613 Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) 594 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;
4use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; 4use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication};
5use itertools::Itertools; 5use itertools::Itertools;
6 6
7use super::{from_chalk, Interner, TypeAliasAsAssocType}; 7use super::{from_chalk, Interner};
8use crate::{db::HirDatabase, CallableDefId}; 8use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId};
9use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; 9use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
10 10
11pub(crate) use unsafe_tls::{set_current_program, with_current_program}; 11pub(crate) use unsafe_tls::{set_current_program, with_current_program};
@@ -41,7 +41,7 @@ impl DebugContext<'_> {
41 id: super::AssocTypeId, 41 id: super::AssocTypeId,
42 fmt: &mut fmt::Formatter<'_>, 42 fmt: &mut fmt::Formatter<'_>,
43 ) -> Result<(), fmt::Error> { 43 ) -> Result<(), fmt::Error> {
44 let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(self.0, id).0; 44 let type_alias: TypeAliasId = from_assoc_type_id(id);
45 let type_alias_data = self.0.type_alias_data(type_alias); 45 let type_alias_data = self.0.type_alias_data(type_alias);
46 let trait_ = match type_alias.lookup(self.0.upcast()).container { 46 let trait_ = match type_alias.lookup(self.0.upcast()).container {
47 AssocContainerId::TraitId(t) => t, 47 AssocContainerId::TraitId(t) => t,
@@ -75,8 +75,7 @@ impl DebugContext<'_> {
75 projection_ty: &chalk_ir::ProjectionTy<Interner>, 75 projection_ty: &chalk_ir::ProjectionTy<Interner>,
76 fmt: &mut fmt::Formatter<'_>, 76 fmt: &mut fmt::Formatter<'_>,
77 ) -> Result<(), fmt::Error> { 77 ) -> Result<(), fmt::Error> {
78 let type_alias: TypeAliasId = 78 let type_alias = from_assoc_type_id(projection_ty.associated_ty_id);
79 from_chalk::<TypeAliasAsAssocType, _>(self.0, projection_ty.associated_ty_id).0;
80 let type_alias_data = self.0.type_alias_data(type_alias); 79 let type_alias_data = self.0.type_alias_data(type_alias);
81 let trait_ = match type_alias.lookup(self.0.upcast()).container { 80 let trait_ = match type_alias.lookup(self.0.upcast()).container {
82 AssocContainerId::TraitId(t) => t, 81 AssocContainerId::TraitId(t) => t,