aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk/mapping.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk/mapping.rs')
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs273
1 files changed, 83 insertions, 190 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 3a08b67e9..05a4bf0df 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
6use chalk_ir::{ 6use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData};
7 cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex,
8 UniverseIndex,
9};
10use chalk_solve::rust_ir; 7use chalk_solve::rust_ir;
11 8
12use base_db::salsa::InternKey; 9use base_db::salsa::InternKey;
@@ -14,10 +11,11 @@ use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId};
14 11
15use crate::{ 12use 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, GenericPredicate, InEnvironment, OpaqueTy,
20 OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, TraitRef, Ty, 18 ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty,
21}; 19};
22 20
23use super::interner::*; 21use super::interner::*;
@@ -26,71 +24,62 @@ use super::*;
26impl ToChalk for Ty { 24impl 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, 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,
36 sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic }, 34 sig,
37 substitution, 35 substitution,
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_id;
93 let substitution = proj_ty.parameters.to_chalk(db); 82 let substitution = proj_ty.substitution.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,
96 substitution, 85 substitution,
@@ -98,17 +87,17 @@ impl ToChalk for Ty {
98 .cast(&Interner) 87 .cast(&Interner)
99 .intern(&Interner) 88 .intern(&Interner)
100 } 89 }
101 Ty::Placeholder(id) => { 90 TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
102 let interned_id = db.intern_type_param_id(id); 91 let opaque_ty_id = opaque_ty.opaque_ty_id;
103 PlaceholderIndex { 92 let substitution = opaque_ty.substitution.to_chalk(db);
104 ui: UniverseIndex::ROOT, 93 chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution })
105 idx: interned_id.as_intern_id().as_usize(), 94 .cast(&Interner)
106 } 95 .intern(&Interner)
107 .to_ty::<Interner>(&Interner) 96 }
108 } 97 TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner),
109 Ty::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), 98 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
110 Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"), 99 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"),
111 Ty::Dyn(predicates) => { 100 TyKind::Dyn(predicates) => {
112 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( 101 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
113 &Interner, 102 &Interner,
114 predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), 103 predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)),
@@ -119,43 +108,30 @@ impl ToChalk for Ty {
119 }; 108 };
120 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) 109 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
121 } 110 }
122 Ty::Alias(AliasTy::Opaque(opaque_ty)) => { 111 TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner),
123 let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db);
124 let substitution = opaque_ty.parameters.to_chalk(db);
125 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
126 opaque_ty_id,
127 substitution,
128 }))
129 .intern(&Interner)
130 }
131 Ty::Unknown => chalk_ir::TyKind::Error.intern(&Interner),
132 } 112 }
133 } 113 }
134 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { 114 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
135 match chalk.data(&Interner).kind.clone() { 115 match chalk.data(&Interner).kind.clone() {
136 chalk_ir::TyKind::Error => Ty::Unknown, 116 chalk_ir::TyKind::Error => TyKind::Unknown,
137 chalk_ir::TyKind::Array(ty, _size) => Ty::Array(Substs::single(from_chalk(db, ty))), 117 chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(Substs::single(from_chalk(db, ty))),
138 chalk_ir::TyKind::Placeholder(idx) => { 118 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)) => { 119 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
146 let associated_ty = 120 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); 121 let parameters = from_chalk(db, proj.substitution);
149 Ty::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) 122 TyKind::Alias(AliasTy::Projection(ProjectionTy {
123 associated_ty_id: associated_ty,
124 substitution: parameters,
125 }))
150 } 126 }
151 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { 127 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
152 let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); 128 let opaque_ty_id = opaque_ty.opaque_ty_id;
153 let parameters = from_chalk(db, opaque_ty.substitution); 129 let parameters = from_chalk(db, opaque_ty.substitution);
154 Ty::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) 130 TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters }))
155 } 131 }
156 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 132 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
157 num_binders, 133 num_binders,
158 sig: chalk_ir::FnSig { variadic, .. }, 134 sig,
159 substitution, 135 substitution,
160 .. 136 ..
161 }) => { 137 }) => {
@@ -164,14 +140,10 @@ impl ToChalk for Ty {
164 db, 140 db,
165 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), 141 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"),
166 ); 142 );
167 Ty::Function(FnPointer { 143 TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs })
168 num_args: (substs.len() - 1),
169 sig: FnSig { variadic },
170 substs,
171 })
172 } 144 }
173 chalk_ir::TyKind::BoundVar(idx) => Ty::BoundVar(idx), 145 chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx),
174 chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, 146 chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown,
175 chalk_ir::TyKind::Dyn(where_clauses) => { 147 chalk_ir::TyKind::Dyn(where_clauses) => {
176 assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); 148 assert_eq!(where_clauses.bounds.binders.len(&Interner), 1);
177 let predicates = where_clauses 149 let predicates = where_clauses
@@ -180,49 +152,43 @@ impl ToChalk for Ty {
180 .iter(&Interner) 152 .iter(&Interner)
181 .map(|c| from_chalk(db, c.clone())) 153 .map(|c| from_chalk(db, c.clone()))
182 .collect(); 154 .collect();
183 Ty::Dyn(predicates) 155 TyKind::Dyn(predicates)
184 } 156 }
185 157
186 chalk_ir::TyKind::Adt(adt_id, subst) => Ty::Adt(adt_id, from_chalk(db, subst)), 158 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( 159 chalk_ir::TyKind::AssociatedType(type_id, subst) => {
188 from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0, 160 TyKind::AssociatedType(type_id, from_chalk(db, subst))
189 from_chalk(db, subst), 161 }
190 ),
191 162
192 chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { 163 chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => {
193 Ty::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) 164 TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst))
194 } 165 }
195 166
196 chalk_ir::TyKind::Scalar(scalar) => Ty::Scalar(scalar), 167 chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar),
197 chalk_ir::TyKind::Tuple(cardinality, subst) => { 168 chalk_ir::TyKind::Tuple(cardinality, subst) => {
198 Ty::Tuple(cardinality, from_chalk(db, subst)) 169 TyKind::Tuple(cardinality, from_chalk(db, subst))
199 } 170 }
200 chalk_ir::TyKind::Raw(mutability, ty) => { 171 chalk_ir::TyKind::Raw(mutability, ty) => {
201 Ty::Raw(mutability, Substs::single(from_chalk(db, ty))) 172 TyKind::Raw(mutability, Substs::single(from_chalk(db, ty)))
202 } 173 }
203 chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), 174 chalk_ir::TyKind::Slice(ty) => TyKind::Slice(Substs::single(from_chalk(db, ty))),
204 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { 175 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => {
205 Ty::Ref(mutability, Substs::single(from_chalk(db, ty))) 176 TyKind::Ref(mutability, Substs::single(from_chalk(db, ty)))
206 } 177 }
207 chalk_ir::TyKind::Str => Ty::Str, 178 chalk_ir::TyKind::Str => TyKind::Str,
208 chalk_ir::TyKind::Never => Ty::Never, 179 chalk_ir::TyKind::Never => TyKind::Never,
209 180
210 chalk_ir::TyKind::FnDef(fn_def_id, subst) => { 181 chalk_ir::TyKind::FnDef(fn_def_id, subst) => {
211 Ty::FnDef(from_chalk(db, fn_def_id), from_chalk(db, subst)) 182 TyKind::FnDef(fn_def_id, from_chalk(db, subst))
212 } 183 }
213 184
214 chalk_ir::TyKind::Closure(id, subst) => { 185 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 186
220 chalk_ir::TyKind::Foreign(foreign_def_id) => { 187 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 188 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
224 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME 189 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
225 } 190 }
191 .intern(&Interner)
226 } 192 }
227} 193}
228 194
@@ -298,21 +264,6 @@ impl ToChalk for hir_def::TraitId {
298 } 264 }
299} 265}
300 266
301impl 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
316impl ToChalk for hir_def::ImplId { 267impl ToChalk for hir_def::ImplId {
317 type Chalk = ImplId; 268 type Chalk = ImplId;
318 269
@@ -337,34 +288,6 @@ impl ToChalk for CallableDefId {
337 } 288 }
338} 289}
339 290
340pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId);
341
342impl 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
354pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId);
355
356impl 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
368pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); 291pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
369 292
370impl ToChalk for TypeAliasAsValue { 293impl ToChalk for TypeAliasAsValue {
@@ -446,8 +369,8 @@ impl ToChalk for ProjectionTy {
446 369
447 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { 370 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
448 chalk_ir::ProjectionTy { 371 chalk_ir::ProjectionTy {
449 associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), 372 associated_ty_id: self.associated_ty_id,
450 substitution: self.parameters.to_chalk(db), 373 substitution: self.substitution.to_chalk(db),
451 } 374 }
452 } 375 }
453 376
@@ -456,12 +379,8 @@ impl ToChalk for ProjectionTy {
456 projection_ty: chalk_ir::ProjectionTy<Interner>, 379 projection_ty: chalk_ir::ProjectionTy<Interner>,
457 ) -> ProjectionTy { 380 ) -> ProjectionTy {
458 ProjectionTy { 381 ProjectionTy {
459 associated_ty: from_chalk::<TypeAliasAsAssocType, _>( 382 associated_ty_id: projection_ty.associated_ty_id,
460 db, 383 substitution: from_chalk(db, projection_ty.substitution),
461 projection_ty.associated_ty_id,
462 )
463 .0,
464 parameters: from_chalk(db, projection_ty.substitution),
465 } 384 }
466 } 385 }
467} 386}
@@ -536,31 +455,6 @@ where
536 } 455 }
537} 456}
538 457
539impl ToChalk for Arc<TraitEnvironment> {
540 type Chalk = chalk_ir::Environment<Interner>;
541
542 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Environment<Interner> {
543 let mut clauses = Vec::new();
544 for pred in &self.predicates {
545 if pred.is_error() {
546 // for env, we just ignore errors
547 continue;
548 }
549 let program_clause: chalk_ir::ProgramClause<Interner> =
550 pred.clone().to_chalk(db).cast(&Interner);
551 clauses.push(program_clause.into_from_env_clause(&Interner));
552 }
553 chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses)
554 }
555
556 fn from_chalk(
557 _db: &dyn HirDatabase,
558 _env: chalk_ir::Environment<Interner>,
559 ) -> Arc<TraitEnvironment> {
560 unimplemented!()
561 }
562}
563
564impl<T: ToChalk> ToChalk for InEnvironment<T> 458impl<T: ToChalk> ToChalk for InEnvironment<T>
565where 459where
566 T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>, 460 T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>,
@@ -569,19 +463,16 @@ where
569 463
570 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { 464 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> {
571 chalk_ir::InEnvironment { 465 chalk_ir::InEnvironment {
572 environment: self.environment.to_chalk(db), 466 environment: self.environment.env.clone(),
573 goal: self.value.to_chalk(db), 467 goal: self.value.to_chalk(db),
574 } 468 }
575 } 469 }
576 470
577 fn from_chalk( 471 fn from_chalk(
578 db: &dyn HirDatabase, 472 _db: &dyn HirDatabase,
579 in_env: chalk_ir::InEnvironment<T::Chalk>, 473 _in_env: chalk_ir::InEnvironment<T::Chalk>,
580 ) -> InEnvironment<T> { 474 ) -> InEnvironment<T> {
581 InEnvironment { 475 unimplemented!()
582 environment: from_chalk(db, in_env.environment),
583 value: from_chalk(db, in_env.goal),
584 }
585 } 476 }
586} 477}
587 478
@@ -639,22 +530,24 @@ pub(super) fn generic_predicate_to_inline_bound(
639 Some(rust_ir::InlineBound::TraitBound(trait_bound)) 530 Some(rust_ir::InlineBound::TraitBound(trait_bound))
640 } 531 }
641 GenericPredicate::Projection(proj) => { 532 GenericPredicate::Projection(proj) => {
642 if &proj.projection_ty.parameters[0] != self_ty { 533 if &proj.projection_ty.substitution[0] != self_ty {
643 return None; 534 return None;
644 } 535 }
645 let trait_ = match proj.projection_ty.associated_ty.lookup(db.upcast()).container { 536 let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty_id)
537 .lookup(db.upcast())
538 .container
539 {
646 AssocContainerId::TraitId(t) => t, 540 AssocContainerId::TraitId(t) => t,
647 _ => panic!("associated type not in trait"), 541 _ => panic!("associated type not in trait"),
648 }; 542 };
649 let args_no_self = proj.projection_ty.parameters[1..] 543 let args_no_self = proj.projection_ty.substitution[1..]
650 .iter() 544 .iter()
651 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 545 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
652 .collect(); 546 .collect();
653 let alias_eq_bound = rust_ir::AliasEqBound { 547 let alias_eq_bound = rust_ir::AliasEqBound {
654 value: proj.ty.clone().to_chalk(db), 548 value: proj.ty.clone().to_chalk(db),
655 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, 549 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
656 associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) 550 associated_ty_id: proj.projection_ty.associated_ty_id,
657 .to_chalk(db),
658 parameters: Vec::new(), // FIXME we don't support generic associated types yet 551 parameters: Vec::new(), // FIXME we don't support generic associated types yet
659 }; 552 };
660 Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) 553 Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound))