diff options
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 66 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 202 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/tls.rs | 9 |
4 files changed, 102 insertions, 177 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 1a2a3a8c7..ef1e6b2df 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -17,16 +17,18 @@ use super::ChalkContext; | |||
17 | use crate::{ | 17 | use crate::{ |
18 | db::HirDatabase, | 18 | db::HirDatabase, |
19 | display::HirDisplay, | 19 | display::HirDisplay, |
20 | from_assoc_type_id, | ||
20 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, | 21 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, |
22 | to_assoc_type_id, | ||
21 | utils::generics, | 23 | utils::generics, |
22 | BoundVar, CallableDefId, CallableSig, DebruijnIndex, GenericPredicate, ProjectionPredicate, | 24 | BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, GenericPredicate, |
23 | ProjectionTy, Substs, TraitRef, Ty, | 25 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TyKind, |
24 | }; | 26 | }; |
25 | use mapping::{ | 27 | use mapping::{ |
26 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsAssocType, | 28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, |
27 | TypeAliasAsValue, | ||
28 | }; | 29 | }; |
29 | 30 | ||
31 | pub use self::interner::Interner; | ||
30 | pub(crate) use self::interner::*; | 32 | pub(crate) use self::interner::*; |
31 | 33 | ||
32 | pub(super) mod tls; | 34 | pub(super) mod tls; |
@@ -90,7 +92,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
90 | ty: &Ty, | 92 | ty: &Ty, |
91 | binders: &CanonicalVarKinds<Interner>, | 93 | binders: &CanonicalVarKinds<Interner>, |
92 | ) -> Option<chalk_ir::TyVariableKind> { | 94 | ) -> Option<chalk_ir::TyVariableKind> { |
93 | if let Ty::BoundVar(bv) = ty { | 95 | if let TyKind::BoundVar(bv) = ty.interned(&Interner) { |
94 | let binders = binders.as_slice(&Interner); | 96 | let binders = binders.as_slice(&Interner); |
95 | if bv.debruijn == DebruijnIndex::INNERMOST { | 97 | if bv.debruijn == DebruijnIndex::INNERMOST { |
96 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { | 98 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { |
@@ -175,10 +177,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
175 | } | 177 | } |
176 | 178 | ||
177 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { | 179 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { |
178 | let interned_id = crate::db::InternedOpaqueTyId::from(id); | 180 | let full_id = self.db.lookup_intern_impl_trait_id(id.into()); |
179 | let full_id = self.db.lookup_intern_impl_trait_id(interned_id); | ||
180 | let bound = match full_id { | 181 | let bound = match full_id { |
181 | crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 182 | crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => { |
182 | let datas = self | 183 | let datas = self |
183 | .db | 184 | .db |
184 | .return_type_impl_traits(func) | 185 | .return_type_impl_traits(func) |
@@ -200,7 +201,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
200 | let num_vars = datas.num_binders; | 201 | let num_vars = datas.num_binders; |
201 | make_binders(bound, num_vars) | 202 | make_binders(bound, num_vars) |
202 | } | 203 | } |
203 | crate::OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 204 | crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
204 | if let Some((future_trait, future_output)) = self | 205 | if let Some((future_trait, future_output)) = self |
205 | .db | 206 | .db |
206 | .lang_item(self.krate, "future_trait".into()) | 207 | .lang_item(self.krate, "future_trait".into()) |
@@ -220,21 +221,25 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
220 | let impl_bound = GenericPredicate::Implemented(TraitRef { | 221 | let impl_bound = GenericPredicate::Implemented(TraitRef { |
221 | trait_: future_trait, | 222 | trait_: future_trait, |
222 | // Self type as the first parameter. | 223 | // Self type as the first parameter. |
223 | substs: Substs::single(Ty::BoundVar(BoundVar { | 224 | substs: Substs::single( |
224 | debruijn: DebruijnIndex::INNERMOST, | 225 | TyKind::BoundVar(BoundVar { |
225 | index: 0, | 226 | debruijn: DebruijnIndex::INNERMOST, |
226 | })), | 227 | index: 0, |
228 | }) | ||
229 | .intern(&Interner), | ||
230 | ), | ||
227 | }); | 231 | }); |
228 | let proj_bound = GenericPredicate::Projection(ProjectionPredicate { | 232 | let proj_bound = GenericPredicate::Projection(ProjectionPredicate { |
229 | // The parameter of the opaque type. | 233 | // The parameter of the opaque type. |
230 | ty: Ty::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }), | 234 | ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }) |
235 | .intern(&Interner), | ||
231 | projection_ty: ProjectionTy { | 236 | projection_ty: ProjectionTy { |
232 | associated_ty: future_output, | 237 | associated_ty: to_assoc_type_id(future_output), |
233 | // Self type as the first parameter. | 238 | // Self type as the first parameter. |
234 | parameters: Substs::single(Ty::BoundVar(BoundVar::new( | 239 | parameters: Substs::single( |
235 | DebruijnIndex::INNERMOST, | 240 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) |
236 | 0, | 241 | .intern(&Interner), |
237 | ))), | 242 | ), |
238 | }, | 243 | }, |
239 | }); | 244 | }); |
240 | let bound = OpaqueTyDatumBound { | 245 | let bound = OpaqueTyDatumBound { |
@@ -263,7 +268,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
263 | 268 | ||
264 | fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { | 269 | fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { |
265 | // FIXME: actually provide the hidden type; it is relevant for auto traits | 270 | // FIXME: actually provide the hidden type; it is relevant for auto traits |
266 | Ty::Unknown.to_chalk(self.db) | 271 | TyKind::Unknown.intern(&Interner).to_chalk(self.db) |
267 | } | 272 | } |
268 | 273 | ||
269 | fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { | 274 | fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { |
@@ -378,7 +383,7 @@ pub(crate) fn associated_ty_data_query( | |||
378 | id: AssocTypeId, | 383 | id: AssocTypeId, |
379 | ) -> Arc<AssociatedTyDatum> { | 384 | ) -> Arc<AssociatedTyDatum> { |
380 | debug!("associated_ty_data {:?}", id); | 385 | debug!("associated_ty_data {:?}", id); |
381 | let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(db, id).0; | 386 | let type_alias: TypeAliasId = from_assoc_type_id(id); |
382 | let trait_ = match type_alias.lookup(db.upcast()).container { | 387 | let trait_ = match type_alias.lookup(db.upcast()).container { |
383 | AssocContainerId::TraitId(t) => t, | 388 | AssocContainerId::TraitId(t) => t, |
384 | _ => panic!("associated type not in trait"), | 389 | _ => panic!("associated type not in trait"), |
@@ -391,11 +396,12 @@ pub(crate) fn associated_ty_data_query( | |||
391 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 396 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
392 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 397 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
393 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 398 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
394 | let self_ty = Ty::BoundVar(crate::BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)); | 399 | let self_ty = |
400 | TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(&Interner); | ||
395 | let bounds = type_alias_data | 401 | let bounds = type_alias_data |
396 | .bounds | 402 | .bounds |
397 | .iter() | 403 | .iter() |
398 | .flat_map(|bound| GenericPredicate::from_type_bound(&ctx, bound, self_ty.clone())) | 404 | .flat_map(|bound| ctx.lower_type_bound(bound, self_ty.clone())) |
399 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) | 405 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) |
400 | .map(|bound| make_binders(bound.shifted_in(&Interner), 0)) | 406 | .map(|bound| make_binders(bound.shifted_in(&Interner), 0)) |
401 | .collect(); | 407 | .collect(); |
@@ -432,10 +438,8 @@ pub(crate) fn trait_datum_query( | |||
432 | fundamental: false, | 438 | fundamental: false, |
433 | }; | 439 | }; |
434 | let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); | 440 | let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); |
435 | let associated_ty_ids = trait_data | 441 | let associated_ty_ids = |
436 | .associated_types() | 442 | trait_data.associated_types().map(|type_alias| to_assoc_type_id(type_alias)).collect(); |
437 | .map(|type_alias| TypeAliasAsAssocType(type_alias).to_chalk(db)) | ||
438 | .collect(); | ||
439 | let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; | 443 | let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; |
440 | let well_known = | 444 | let well_known = |
441 | lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); | 445 | lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); |
@@ -617,7 +621,7 @@ fn type_alias_associated_ty_value( | |||
617 | let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; | 621 | let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; |
618 | let value = rust_ir::AssociatedTyValue { | 622 | let value = rust_ir::AssociatedTyValue { |
619 | impl_id: impl_id.to_chalk(db), | 623 | impl_id: impl_id.to_chalk(db), |
620 | associated_ty_id: TypeAliasAsAssocType(assoc_ty).to_chalk(db), | 624 | associated_ty_id: to_assoc_type_id(assoc_ty), |
621 | value: make_binders(value_bound, ty.num_binders), | 625 | value: make_binders(value_bound, ty.num_binders), |
622 | }; | 626 | }; |
623 | Arc::new(value) | 627 | Arc::new(value) |
@@ -711,14 +715,14 @@ impl From<crate::db::InternedOpaqueTyId> for OpaqueTyId { | |||
711 | } | 715 | } |
712 | } | 716 | } |
713 | 717 | ||
714 | impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId { | 718 | impl From<chalk_ir::ClosureId<Interner>> for crate::db::InternedClosureId { |
715 | fn from(id: chalk_ir::ClosureId<Interner>) -> Self { | 719 | fn from(id: chalk_ir::ClosureId<Interner>) -> Self { |
716 | Self::from_intern_id(id.0) | 720 | Self::from_intern_id(id.0) |
717 | } | 721 | } |
718 | } | 722 | } |
719 | 723 | ||
720 | impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> { | 724 | impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> { |
721 | fn from(id: crate::db::ClosureId) -> Self { | 725 | fn from(id: crate::db::InternedClosureId) -> Self { |
722 | chalk_ir::ClosureId(id.as_intern_id()) | 726 | chalk_ir::ClosureId(id.as_intern_id()) |
723 | } | 727 | } |
724 | } | 728 | } |
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 54bd1c724..1dc3f497d 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -12,7 +12,6 @@ pub struct Interner; | |||
12 | 12 | ||
13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; | 14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; |
15 | pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | ||
16 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; | 15 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; |
17 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; | 16 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; |
18 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; | 17 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; |
@@ -21,7 +20,6 @@ pub(crate) type ImplId = chalk_ir::ImplId<Interner>; | |||
21 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; | 20 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; |
22 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; | 21 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; |
23 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; | 22 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; |
24 | pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>; | ||
25 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; | 23 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; |
26 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | 24 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; |
27 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; | 25 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index b0415e8b0..2a66a2310 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -3,10 +3,7 @@ | |||
3 | //! Chalk (in both directions); plus some helper functions for more specialized | 3 | //! Chalk (in both directions); plus some helper functions for more specialized |
4 | //! conversions. | 4 | //! conversions. |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData}; |
7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, | ||
8 | UniverseIndex, | ||
9 | }; | ||
10 | use chalk_solve::rust_ir; | 7 | use chalk_solve::rust_ir; |
11 | 8 | ||
12 | use base_db::salsa::InternKey; | 9 | use base_db::salsa::InternKey; |
@@ -14,10 +11,11 @@ use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId}; | |||
14 | 11 | ||
15 | use crate::{ | 12 | use crate::{ |
16 | db::HirDatabase, | 13 | db::HirDatabase, |
14 | from_assoc_type_id, | ||
17 | primitive::UintTy, | 15 | primitive::UintTy, |
18 | traits::{Canonical, Obligation}, | 16 | traits::{Canonical, Obligation}, |
19 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, | 17 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
20 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
21 | }; | 19 | }; |
22 | 20 | ||
23 | use super::interner::*; | 21 | use super::interner::*; |
@@ -26,10 +24,10 @@ use super::*; | |||
26 | impl ToChalk for Ty { | 24 | impl ToChalk for Ty { |
27 | type Chalk = chalk_ir::Ty<Interner>; | 25 | type Chalk = chalk_ir::Ty<Interner>; |
28 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { | 26 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { |
29 | match self { | 27 | match self.0 { |
30 | Ty::Ref(m, parameters) => ref_to_chalk(db, m, parameters), | 28 | TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), |
31 | Ty::Array(parameters) => array_to_chalk(db, parameters), | 29 | TyKind::Array(parameters) => array_to_chalk(db, parameters), |
32 | Ty::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { | 30 | TyKind::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { |
33 | let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); | 31 | let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); |
34 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 32 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
35 | num_binders: 0, | 33 | num_binders: 0, |
@@ -38,58 +36,49 @@ impl ToChalk for Ty { | |||
38 | }) | 36 | }) |
39 | .intern(&Interner) | 37 | .intern(&Interner) |
40 | } | 38 | } |
41 | Ty::AssociatedType(type_alias, substs) => { | 39 | 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); | 40 | let substitution = substs.to_chalk(db); |
45 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) | 41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
46 | } | 42 | } |
47 | 43 | ||
48 | Ty::OpaqueType(impl_trait_id, substs) => { | 44 | TyKind::OpaqueType(id, substs) => { |
49 | let id = impl_trait_id.to_chalk(db); | ||
50 | let substitution = substs.to_chalk(db); | 45 | let substitution = substs.to_chalk(db); |
51 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | 46 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) |
52 | } | 47 | } |
53 | 48 | ||
54 | Ty::ForeignType(type_alias) => { | 49 | TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner), |
55 | let foreign_type = TypeAliasAsForeignType(type_alias); | ||
56 | let foreign_type_id = foreign_type.to_chalk(db); | ||
57 | chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner) | ||
58 | } | ||
59 | 50 | ||
60 | Ty::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), | 51 | TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), |
61 | 52 | ||
62 | Ty::Tuple(cardinality, substs) => { | 53 | TyKind::Tuple(cardinality, substs) => { |
63 | let substitution = substs.to_chalk(db); | 54 | let substitution = substs.to_chalk(db); |
64 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) | 55 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) |
65 | } | 56 | } |
66 | Ty::Raw(mutability, substs) => { | 57 | TyKind::Raw(mutability, substs) => { |
67 | let ty = substs[0].clone().to_chalk(db); | 58 | let ty = substs[0].clone().to_chalk(db); |
68 | chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) | 59 | chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) |
69 | } | 60 | } |
70 | Ty::Slice(substs) => { | 61 | TyKind::Slice(substs) => { |
71 | chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) | 62 | chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) |
72 | } | 63 | } |
73 | Ty::Str => chalk_ir::TyKind::Str.intern(&Interner), | 64 | TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner), |
74 | Ty::FnDef(callable_def, substs) => { | 65 | TyKind::FnDef(id, substs) => { |
75 | let id = callable_def.to_chalk(db); | ||
76 | let substitution = substs.to_chalk(db); | 66 | let substitution = substs.to_chalk(db); |
77 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) | 67 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) |
78 | } | 68 | } |
79 | Ty::Never => chalk_ir::TyKind::Never.intern(&Interner), | 69 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), |
80 | 70 | ||
81 | Ty::Closure(def, expr, substs) => { | 71 | TyKind::Closure(closure_id, substs) => { |
82 | let closure_id = db.intern_closure((def, expr)); | ||
83 | let substitution = substs.to_chalk(db); | 72 | let substitution = substs.to_chalk(db); |
84 | chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) | 73 | chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner) |
85 | } | 74 | } |
86 | 75 | ||
87 | Ty::Adt(adt_id, substs) => { | 76 | TyKind::Adt(adt_id, substs) => { |
88 | let substitution = substs.to_chalk(db); | 77 | let substitution = substs.to_chalk(db); |
89 | chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) | 78 | chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) |
90 | } | 79 | } |
91 | Ty::Alias(AliasTy::Projection(proj_ty)) => { | 80 | TyKind::Alias(AliasTy::Projection(proj_ty)) => { |
92 | let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); | 81 | let associated_ty_id = proj_ty.associated_ty; |
93 | let substitution = proj_ty.parameters.to_chalk(db); | 82 | let substitution = proj_ty.parameters.to_chalk(db); |
94 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { | 83 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { |
95 | associated_ty_id, | 84 | associated_ty_id, |
@@ -98,17 +87,10 @@ impl ToChalk for Ty { | |||
98 | .cast(&Interner) | 87 | .cast(&Interner) |
99 | .intern(&Interner) | 88 | .intern(&Interner) |
100 | } | 89 | } |
101 | Ty::Placeholder(id) => { | 90 | TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), |
102 | let interned_id = db.intern_type_param_id(id); | 91 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
103 | PlaceholderIndex { | 92 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
104 | ui: UniverseIndex::ROOT, | 93 | TyKind::Dyn(predicates) => { |
105 | idx: interned_id.as_intern_id().as_usize(), | ||
106 | } | ||
107 | .to_ty::<Interner>(&Interner) | ||
108 | } | ||
109 | Ty::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | ||
110 | Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"), | ||
111 | Ty::Dyn(predicates) => { | ||
112 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( | 94 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
113 | &Interner, | 95 | &Interner, |
114 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), | 96 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), |
@@ -119,8 +101,8 @@ impl ToChalk for Ty { | |||
119 | }; | 101 | }; |
120 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 102 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
121 | } | 103 | } |
122 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { | 104 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
123 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 105 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
124 | let substitution = opaque_ty.parameters.to_chalk(db); | 106 | let substitution = opaque_ty.parameters.to_chalk(db); |
125 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 107 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
126 | opaque_ty_id, | 108 | opaque_ty_id, |
@@ -128,30 +110,23 @@ impl ToChalk for Ty { | |||
128 | })) | 110 | })) |
129 | .intern(&Interner) | 111 | .intern(&Interner) |
130 | } | 112 | } |
131 | Ty::Unknown => chalk_ir::TyKind::Error.intern(&Interner), | 113 | TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner), |
132 | } | 114 | } |
133 | } | 115 | } |
134 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { | 116 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { |
135 | match chalk.data(&Interner).kind.clone() { | 117 | match chalk.data(&Interner).kind.clone() { |
136 | chalk_ir::TyKind::Error => Ty::Unknown, | 118 | chalk_ir::TyKind::Error => TyKind::Unknown, |
137 | chalk_ir::TyKind::Array(ty, _size) => Ty::Array(Substs::single(from_chalk(db, ty))), | 119 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))), |
138 | chalk_ir::TyKind::Placeholder(idx) => { | 120 | chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), |
139 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
140 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( | ||
141 | crate::salsa::InternId::from(idx.idx), | ||
142 | ); | ||
143 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) | ||
144 | } | ||
145 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 121 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
146 | let associated_ty = | 122 | let associated_ty = proj.associated_ty_id; |
147 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; | ||
148 | let parameters = from_chalk(db, proj.substitution); | 123 | let parameters = from_chalk(db, proj.substitution); |
149 | Ty::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) | 124 | TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) |
150 | } | 125 | } |
151 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 126 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
152 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 127 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
153 | let parameters = from_chalk(db, opaque_ty.substitution); | 128 | let parameters = from_chalk(db, opaque_ty.substitution); |
154 | Ty::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) | 129 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) |
155 | } | 130 | } |
156 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 131 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
157 | num_binders, | 132 | num_binders, |
@@ -164,14 +139,14 @@ impl ToChalk for Ty { | |||
164 | db, | 139 | db, |
165 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 140 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
166 | ); | 141 | ); |
167 | Ty::Function(FnPointer { | 142 | TyKind::Function(FnPointer { |
168 | num_args: (substs.len() - 1), | 143 | num_args: (substs.len() - 1), |
169 | sig: FnSig { variadic }, | 144 | sig: FnSig { variadic }, |
170 | substs, | 145 | substs, |
171 | }) | 146 | }) |
172 | } | 147 | } |
173 | chalk_ir::TyKind::BoundVar(idx) => Ty::BoundVar(idx), | 148 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), |
174 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, | 149 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, |
175 | chalk_ir::TyKind::Dyn(where_clauses) => { | 150 | chalk_ir::TyKind::Dyn(where_clauses) => { |
176 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); | 151 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); |
177 | let predicates = where_clauses | 152 | let predicates = where_clauses |
@@ -180,49 +155,43 @@ impl ToChalk for Ty { | |||
180 | .iter(&Interner) | 155 | .iter(&Interner) |
181 | .map(|c| from_chalk(db, c.clone())) | 156 | .map(|c| from_chalk(db, c.clone())) |
182 | .collect(); | 157 | .collect(); |
183 | Ty::Dyn(predicates) | 158 | TyKind::Dyn(predicates) |
184 | } | 159 | } |
185 | 160 | ||
186 | chalk_ir::TyKind::Adt(adt_id, subst) => Ty::Adt(adt_id, from_chalk(db, subst)), | 161 | chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)), |
187 | chalk_ir::TyKind::AssociatedType(type_id, subst) => Ty::AssociatedType( | 162 | chalk_ir::TyKind::AssociatedType(type_id, subst) => { |
188 | from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0, | 163 | TyKind::AssociatedType(type_id, from_chalk(db, subst)) |
189 | from_chalk(db, subst), | 164 | } |
190 | ), | ||
191 | 165 | ||
192 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | 166 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { |
193 | Ty::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) | 167 | TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst)) |
194 | } | 168 | } |
195 | 169 | ||
196 | chalk_ir::TyKind::Scalar(scalar) => Ty::Scalar(scalar), | 170 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), |
197 | chalk_ir::TyKind::Tuple(cardinality, subst) => { | 171 | chalk_ir::TyKind::Tuple(cardinality, subst) => { |
198 | Ty::Tuple(cardinality, from_chalk(db, subst)) | 172 | TyKind::Tuple(cardinality, from_chalk(db, subst)) |
199 | } | 173 | } |
200 | chalk_ir::TyKind::Raw(mutability, ty) => { | 174 | chalk_ir::TyKind::Raw(mutability, ty) => { |
201 | Ty::Raw(mutability, Substs::single(from_chalk(db, ty))) | 175 | TyKind::Raw(mutability, Substs::single(from_chalk(db, ty))) |
202 | } | 176 | } |
203 | chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), | 177 | chalk_ir::TyKind::Slice(ty) => TyKind::Slice(Substs::single(from_chalk(db, ty))), |
204 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | 178 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { |
205 | Ty::Ref(mutability, Substs::single(from_chalk(db, ty))) | 179 | TyKind::Ref(mutability, Substs::single(from_chalk(db, ty))) |
206 | } | 180 | } |
207 | chalk_ir::TyKind::Str => Ty::Str, | 181 | chalk_ir::TyKind::Str => TyKind::Str, |
208 | chalk_ir::TyKind::Never => Ty::Never, | 182 | chalk_ir::TyKind::Never => TyKind::Never, |
209 | 183 | ||
210 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { | 184 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { |
211 | Ty::FnDef(from_chalk(db, fn_def_id), from_chalk(db, subst)) | 185 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) |
212 | } | 186 | } |
213 | 187 | ||
214 | chalk_ir::TyKind::Closure(id, subst) => { | 188 | chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)), |
215 | let id: crate::db::ClosureId = id.into(); | ||
216 | let (def, expr) = db.lookup_intern_closure(id); | ||
217 | Ty::Closure(def, expr, from_chalk(db, subst)) | ||
218 | } | ||
219 | 189 | ||
220 | chalk_ir::TyKind::Foreign(foreign_def_id) => { | 190 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), |
221 | Ty::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0) | ||
222 | } | ||
223 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME | 191 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME |
224 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME | 192 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME |
225 | } | 193 | } |
194 | .intern(&Interner) | ||
226 | } | 195 | } |
227 | } | 196 | } |
228 | 197 | ||
@@ -298,21 +267,6 @@ impl ToChalk for hir_def::TraitId { | |||
298 | } | 267 | } |
299 | } | 268 | } |
300 | 269 | ||
301 | impl ToChalk for OpaqueTyId { | ||
302 | type Chalk = chalk_ir::OpaqueTyId<Interner>; | ||
303 | |||
304 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> { | ||
305 | db.intern_impl_trait_id(self).into() | ||
306 | } | ||
307 | |||
308 | fn from_chalk( | ||
309 | db: &dyn HirDatabase, | ||
310 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | ||
311 | ) -> OpaqueTyId { | ||
312 | db.lookup_intern_impl_trait_id(opaque_ty_id.into()) | ||
313 | } | ||
314 | } | ||
315 | |||
316 | impl ToChalk for hir_def::ImplId { | 270 | impl ToChalk for hir_def::ImplId { |
317 | type Chalk = ImplId; | 271 | type Chalk = ImplId; |
318 | 272 | ||
@@ -337,34 +291,6 @@ impl ToChalk for CallableDefId { | |||
337 | } | 291 | } |
338 | } | 292 | } |
339 | 293 | ||
340 | pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId); | ||
341 | |||
342 | impl ToChalk for TypeAliasAsAssocType { | ||
343 | type Chalk = AssocTypeId; | ||
344 | |||
345 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { | ||
346 | chalk_ir::AssocTypeId(self.0.as_intern_id()) | ||
347 | } | ||
348 | |||
349 | fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType { | ||
350 | TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0)) | ||
351 | } | ||
352 | } | ||
353 | |||
354 | pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId); | ||
355 | |||
356 | impl ToChalk for TypeAliasAsForeignType { | ||
357 | type Chalk = ForeignDefId; | ||
358 | |||
359 | fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId { | ||
360 | chalk_ir::ForeignDefId(self.0.as_intern_id()) | ||
361 | } | ||
362 | |||
363 | fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType { | ||
364 | TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0)) | ||
365 | } | ||
366 | } | ||
367 | |||
368 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); | 294 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); |
369 | 295 | ||
370 | impl ToChalk for TypeAliasAsValue { | 296 | impl ToChalk for TypeAliasAsValue { |
@@ -446,7 +372,7 @@ impl ToChalk for ProjectionTy { | |||
446 | 372 | ||
447 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { | 373 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { |
448 | chalk_ir::ProjectionTy { | 374 | chalk_ir::ProjectionTy { |
449 | associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), | 375 | associated_ty_id: self.associated_ty, |
450 | substitution: self.parameters.to_chalk(db), | 376 | substitution: self.parameters.to_chalk(db), |
451 | } | 377 | } |
452 | } | 378 | } |
@@ -456,11 +382,7 @@ impl ToChalk for ProjectionTy { | |||
456 | projection_ty: chalk_ir::ProjectionTy<Interner>, | 382 | projection_ty: chalk_ir::ProjectionTy<Interner>, |
457 | ) -> ProjectionTy { | 383 | ) -> ProjectionTy { |
458 | ProjectionTy { | 384 | ProjectionTy { |
459 | associated_ty: from_chalk::<TypeAliasAsAssocType, _>( | 385 | associated_ty: projection_ty.associated_ty_id, |
460 | db, | ||
461 | projection_ty.associated_ty_id, | ||
462 | ) | ||
463 | .0, | ||
464 | parameters: from_chalk(db, projection_ty.substitution), | 386 | parameters: from_chalk(db, projection_ty.substitution), |
465 | } | 387 | } |
466 | } | 388 | } |
@@ -614,7 +536,10 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
614 | if &proj.projection_ty.parameters[0] != self_ty { | 536 | if &proj.projection_ty.parameters[0] != self_ty { |
615 | return None; | 537 | return None; |
616 | } | 538 | } |
617 | let trait_ = match proj.projection_ty.associated_ty.lookup(db.upcast()).container { | 539 | let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty) |
540 | .lookup(db.upcast()) | ||
541 | .container | ||
542 | { | ||
618 | AssocContainerId::TraitId(t) => t, | 543 | AssocContainerId::TraitId(t) => t, |
619 | _ => panic!("associated type not in trait"), | 544 | _ => panic!("associated type not in trait"), |
620 | }; | 545 | }; |
@@ -625,8 +550,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
625 | let alias_eq_bound = rust_ir::AliasEqBound { | 550 | let alias_eq_bound = rust_ir::AliasEqBound { |
626 | value: proj.ty.clone().to_chalk(db), | 551 | value: proj.ty.clone().to_chalk(db), |
627 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, | 552 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, |
628 | associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) | 553 | associated_ty_id: proj.projection_ty.associated_ty, |
629 | .to_chalk(db), | ||
630 | parameters: Vec::new(), // FIXME we don't support generic associated types yet | 554 | parameters: Vec::new(), // FIXME we don't support generic associated types yet |
631 | }; | 555 | }; |
632 | Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) | 556 | 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; | |||
4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; | 4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use super::{from_chalk, Interner, TypeAliasAsAssocType}; | 7 | use super::{from_chalk, Interner}; |
8 | use crate::{db::HirDatabase, CallableDefId}; | 8 | use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId}; |
9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; | 9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; |
10 | 10 | ||
11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; | 11 | pub(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, |