]> git.lizzy.rs Git - rust.git/blob - crates/hir_ty/src/traits/chalk/mapping.rs
c5654f17b7586e33cad233bf418bceb330968f2b
[rust.git] / crates / hir_ty / src / traits / chalk / mapping.rs
1 //! This module contains the implementations of the `ToChalk` trait, which
2 //! handles conversion between our data types and their corresponding types in
3 //! Chalk (in both directions); plus some helper functions for more specialized
4 //! conversions.
5
6 use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData};
7 use chalk_solve::rust_ir;
8
9 use base_db::salsa::InternKey;
10 use hir_def::{GenericDefId, TypeAliasId};
11
12 use crate::{
13     db::HirDatabase, primitive::UintTy, AliasTy, CallableDefId, Canonical, DomainGoal, FnPointer,
14     GenericArg, InEnvironment, OpaqueTy, ProjectionTy, QuantifiedWhereClause, Scalar, Substitution,
15     TraitRef, Ty, TypeWalk, WhereClause,
16 };
17
18 use super::interner::*;
19 use super::*;
20
21 impl ToChalk for Ty {
22     type Chalk = chalk_ir::Ty<Interner>;
23     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
24         match self.into_inner() {
25             TyKind::Ref(m, ty) => ref_to_chalk(db, m, ty),
26             TyKind::Array(ty) => array_to_chalk(db, ty),
27             TyKind::Function(FnPointer { sig, substs, .. }) => {
28                 let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner));
29                 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
30                     num_binders: 0,
31                     sig,
32                     substitution,
33                 })
34                 .intern(&Interner)
35             }
36             TyKind::AssociatedType(assoc_type_id, substs) => {
37                 let substitution = substs.to_chalk(db);
38                 chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner)
39             }
40
41             TyKind::OpaqueType(id, substs) => {
42                 let substitution = substs.to_chalk(db);
43                 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
44             }
45
46             TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner),
47
48             TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner),
49
50             TyKind::Tuple(cardinality, substs) => {
51                 let substitution = substs.to_chalk(db);
52                 chalk_ir::TyKind::Tuple(cardinality, substitution).intern(&Interner)
53             }
54             TyKind::Raw(mutability, ty) => {
55                 let ty = ty.to_chalk(db);
56                 chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner)
57             }
58             TyKind::Slice(ty) => chalk_ir::TyKind::Slice(ty.to_chalk(db)).intern(&Interner),
59             TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner),
60             TyKind::FnDef(id, substs) => {
61                 let substitution = substs.to_chalk(db);
62                 chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner)
63             }
64             TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner),
65
66             TyKind::Closure(closure_id, substs) => {
67                 let substitution = substs.to_chalk(db);
68                 chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner)
69             }
70
71             TyKind::Adt(adt_id, substs) => {
72                 let substitution = substs.to_chalk(db);
73                 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner)
74             }
75             TyKind::Alias(AliasTy::Projection(proj_ty)) => {
76                 let associated_ty_id = proj_ty.associated_ty_id;
77                 let substitution = proj_ty.substitution.to_chalk(db);
78                 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
79                     associated_ty_id,
80                     substitution,
81                 })
82                 .cast(&Interner)
83                 .intern(&Interner)
84             }
85             TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
86                 let opaque_ty_id = opaque_ty.opaque_ty_id;
87                 let substitution = opaque_ty.substitution.to_chalk(db);
88                 chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution })
89                     .cast(&Interner)
90                     .intern(&Interner)
91             }
92             TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner),
93             TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
94             TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"),
95             TyKind::Dyn(dyn_ty) => {
96                 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
97                     &Interner,
98                     dyn_ty.bounds.value.interned().iter().cloned().map(|p| p.to_chalk(db)),
99                 );
100                 let bounded_ty = chalk_ir::DynTy {
101                     bounds: make_binders(where_clauses, 1),
102                     lifetime: LifetimeData::Static.intern(&Interner),
103                 };
104                 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
105             }
106             TyKind::Error => chalk_ir::TyKind::Error.intern(&Interner),
107         }
108     }
109     fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
110         match chalk.data(&Interner).kind.clone() {
111             chalk_ir::TyKind::Error => TyKind::Error,
112             chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(from_chalk(db, ty)),
113             chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
114             chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
115                 let associated_ty = proj.associated_ty_id;
116                 let parameters = from_chalk(db, proj.substitution);
117                 TyKind::Alias(AliasTy::Projection(ProjectionTy {
118                     associated_ty_id: associated_ty,
119                     substitution: parameters,
120                 }))
121             }
122             chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
123                 let opaque_ty_id = opaque_ty.opaque_ty_id;
124                 let parameters = from_chalk(db, opaque_ty.substitution);
125                 TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters }))
126             }
127             chalk_ir::TyKind::Function(chalk_ir::FnPointer {
128                 num_binders,
129                 sig,
130                 substitution,
131                 ..
132             }) => {
133                 assert_eq!(num_binders, 0);
134                 let substs: Substitution = from_chalk(
135                     db,
136                     substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"),
137                 );
138                 TyKind::Function(FnPointer { num_args: (substs.len(&Interner) - 1), sig, substs })
139             }
140             chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx),
141             chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Error,
142             chalk_ir::TyKind::Dyn(where_clauses) => {
143                 assert_eq!(where_clauses.bounds.binders.len(&Interner), 1);
144                 let bounds = where_clauses
145                     .bounds
146                     .skip_binders()
147                     .iter(&Interner)
148                     .map(|c| from_chalk(db, c.clone()));
149                 TyKind::Dyn(crate::DynTy {
150                     bounds: crate::Binders::new(
151                         1,
152                         crate::QuantifiedWhereClauses::from_iter(&Interner, bounds),
153                     ),
154                 })
155             }
156
157             chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)),
158             chalk_ir::TyKind::AssociatedType(type_id, subst) => {
159                 TyKind::AssociatedType(type_id, from_chalk(db, subst))
160             }
161
162             chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => {
163                 TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst))
164             }
165
166             chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar),
167             chalk_ir::TyKind::Tuple(cardinality, subst) => {
168                 TyKind::Tuple(cardinality, from_chalk(db, subst))
169             }
170             chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)),
171             chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)),
172             chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => {
173                 TyKind::Ref(mutability, from_chalk(db, ty))
174             }
175             chalk_ir::TyKind::Str => TyKind::Str,
176             chalk_ir::TyKind::Never => TyKind::Never,
177
178             chalk_ir::TyKind::FnDef(fn_def_id, subst) => {
179                 TyKind::FnDef(fn_def_id, from_chalk(db, subst))
180             }
181
182             chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)),
183
184             chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id),
185             chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
186             chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
187         }
188         .intern(&Interner)
189     }
190 }
191
192 /// We currently don't model lifetimes, but Chalk does. So, we have to insert a
193 /// fake lifetime here, because Chalks built-in logic may expect it to be there.
194 fn ref_to_chalk(
195     db: &dyn HirDatabase,
196     mutability: chalk_ir::Mutability,
197     ty: Ty,
198 ) -> chalk_ir::Ty<Interner> {
199     let arg = ty.to_chalk(db);
200     let lifetime = LifetimeData::Static.intern(&Interner);
201     chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner)
202 }
203
204 /// We currently don't model constants, but Chalk does. So, we have to insert a
205 /// fake constant here, because Chalks built-in logic may expect it to be there.
206 fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> {
207     let arg = ty.to_chalk(db);
208     let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
209     let const_ = chalk_ir::ConstData {
210         ty: usize_ty,
211         value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }),
212     }
213     .intern(&Interner);
214     chalk_ir::TyKind::Array(arg, const_).intern(&Interner)
215 }
216
217 impl ToChalk for GenericArg {
218     type Chalk = chalk_ir::GenericArg<Interner>;
219
220     fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
221         match self.interned() {
222             crate::GenericArgData::Ty(ty) => ty.clone().to_chalk(db).cast(&Interner),
223         }
224     }
225
226     fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
227         match chalk.interned() {
228             chalk_ir::GenericArgData::Ty(ty) => Ty::from_chalk(db, ty.clone()).cast(&Interner),
229             chalk_ir::GenericArgData::Lifetime(_) => unimplemented!(),
230             chalk_ir::GenericArgData::Const(_) => unimplemented!(),
231         }
232     }
233 }
234
235 impl ToChalk for Substitution {
236     type Chalk = chalk_ir::Substitution<Interner>;
237
238     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
239         chalk_ir::Substitution::from_iter(
240             &Interner,
241             self.iter(&Interner).map(|ty| ty.clone().to_chalk(db)),
242         )
243     }
244
245     fn from_chalk(
246         db: &dyn HirDatabase,
247         parameters: chalk_ir::Substitution<Interner>,
248     ) -> Substitution {
249         let tys = parameters.iter(&Interner).map(|p| from_chalk(db, p.clone())).collect();
250         Substitution::intern(tys)
251     }
252 }
253
254 impl ToChalk for TraitRef {
255     type Chalk = chalk_ir::TraitRef<Interner>;
256
257     fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef<Interner> {
258         let trait_id = self.trait_id;
259         let substitution = self.substitution.to_chalk(db);
260         chalk_ir::TraitRef { trait_id, substitution }
261     }
262
263     fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef<Interner>) -> Self {
264         let trait_id = trait_ref.trait_id;
265         let substs = from_chalk(db, trait_ref.substitution);
266         TraitRef { trait_id, substitution: substs }
267     }
268 }
269
270 impl ToChalk for hir_def::TraitId {
271     type Chalk = TraitId;
272
273     fn to_chalk(self, _db: &dyn HirDatabase) -> TraitId {
274         chalk_ir::TraitId(self.as_intern_id())
275     }
276
277     fn from_chalk(_db: &dyn HirDatabase, trait_id: TraitId) -> hir_def::TraitId {
278         InternKey::from_intern_id(trait_id.0)
279     }
280 }
281
282 impl ToChalk for hir_def::ImplId {
283     type Chalk = ImplId;
284
285     fn to_chalk(self, _db: &dyn HirDatabase) -> ImplId {
286         chalk_ir::ImplId(self.as_intern_id())
287     }
288
289     fn from_chalk(_db: &dyn HirDatabase, impl_id: ImplId) -> hir_def::ImplId {
290         InternKey::from_intern_id(impl_id.0)
291     }
292 }
293
294 impl ToChalk for CallableDefId {
295     type Chalk = FnDefId;
296
297     fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId {
298         db.intern_callable_def(self).into()
299     }
300
301     fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDefId {
302         db.lookup_intern_callable_def(fn_def_id.into())
303     }
304 }
305
306 pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
307
308 impl ToChalk for TypeAliasAsValue {
309     type Chalk = AssociatedTyValueId;
310
311     fn to_chalk(self, _db: &dyn HirDatabase) -> AssociatedTyValueId {
312         rust_ir::AssociatedTyValueId(self.0.as_intern_id())
313     }
314
315     fn from_chalk(
316         _db: &dyn HirDatabase,
317         assoc_ty_value_id: AssociatedTyValueId,
318     ) -> TypeAliasAsValue {
319         TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0))
320     }
321 }
322
323 impl ToChalk for WhereClause {
324     type Chalk = chalk_ir::WhereClause<Interner>;
325
326     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::WhereClause<Interner> {
327         match self {
328             WhereClause::Implemented(trait_ref) => {
329                 chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db))
330             }
331             WhereClause::AliasEq(alias_eq) => chalk_ir::WhereClause::AliasEq(alias_eq.to_chalk(db)),
332         }
333     }
334
335     fn from_chalk(
336         db: &dyn HirDatabase,
337         where_clause: chalk_ir::WhereClause<Interner>,
338     ) -> WhereClause {
339         match where_clause {
340             chalk_ir::WhereClause::Implemented(tr) => WhereClause::Implemented(from_chalk(db, tr)),
341             chalk_ir::WhereClause::AliasEq(alias_eq) => {
342                 WhereClause::AliasEq(from_chalk(db, alias_eq))
343             }
344
345             chalk_ir::WhereClause::LifetimeOutlives(_) => {
346                 // we shouldn't get these from Chalk
347                 panic!("encountered LifetimeOutlives from Chalk")
348             }
349
350             chalk_ir::WhereClause::TypeOutlives(_) => {
351                 // we shouldn't get these from Chalk
352                 panic!("encountered TypeOutlives from Chalk")
353             }
354         }
355     }
356 }
357
358 impl ToChalk for ProjectionTy {
359     type Chalk = chalk_ir::ProjectionTy<Interner>;
360
361     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
362         chalk_ir::ProjectionTy {
363             associated_ty_id: self.associated_ty_id,
364             substitution: self.substitution.to_chalk(db),
365         }
366     }
367
368     fn from_chalk(
369         db: &dyn HirDatabase,
370         projection_ty: chalk_ir::ProjectionTy<Interner>,
371     ) -> ProjectionTy {
372         ProjectionTy {
373             associated_ty_id: projection_ty.associated_ty_id,
374             substitution: from_chalk(db, projection_ty.substitution),
375         }
376     }
377 }
378 impl ToChalk for OpaqueTy {
379     type Chalk = chalk_ir::OpaqueTy<Interner>;
380
381     fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
382         chalk_ir::OpaqueTy {
383             opaque_ty_id: self.opaque_ty_id,
384             substitution: self.substitution.to_chalk(db),
385         }
386     }
387
388     fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
389         OpaqueTy {
390             opaque_ty_id: chalk.opaque_ty_id,
391             substitution: from_chalk(db, chalk.substitution),
392         }
393     }
394 }
395
396 impl ToChalk for AliasTy {
397     type Chalk = chalk_ir::AliasTy<Interner>;
398
399     fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
400         match self {
401             AliasTy::Projection(projection_ty) => {
402                 chalk_ir::AliasTy::Projection(projection_ty.to_chalk(db))
403             }
404             AliasTy::Opaque(opaque_ty) => chalk_ir::AliasTy::Opaque(opaque_ty.to_chalk(db)),
405         }
406     }
407
408     fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
409         match chalk {
410             chalk_ir::AliasTy::Projection(projection_ty) => {
411                 AliasTy::Projection(from_chalk(db, projection_ty))
412             }
413             chalk_ir::AliasTy::Opaque(opaque_ty) => AliasTy::Opaque(from_chalk(db, opaque_ty)),
414         }
415     }
416 }
417
418 impl ToChalk for AliasEq {
419     type Chalk = chalk_ir::AliasEq<Interner>;
420
421     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasEq<Interner> {
422         chalk_ir::AliasEq { alias: self.alias.to_chalk(db), ty: self.ty.to_chalk(db) }
423     }
424
425     fn from_chalk(db: &dyn HirDatabase, alias_eq: chalk_ir::AliasEq<Interner>) -> Self {
426         AliasEq { alias: from_chalk(db, alias_eq.alias), ty: from_chalk(db, alias_eq.ty) }
427     }
428 }
429
430 impl ToChalk for DomainGoal {
431     type Chalk = chalk_ir::DomainGoal<Interner>;
432
433     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
434         match self {
435             DomainGoal::Holds(WhereClause::Implemented(tr)) => tr.to_chalk(db).cast(&Interner),
436             DomainGoal::Holds(WhereClause::AliasEq(alias_eq)) => {
437                 alias_eq.to_chalk(db).cast(&Interner)
438             }
439         }
440     }
441
442     fn from_chalk(_db: &dyn HirDatabase, _goal: chalk_ir::DomainGoal<Interner>) -> Self {
443         unimplemented!()
444     }
445 }
446
447 impl<T> ToChalk for Canonical<T>
448 where
449     T: ToChalk,
450     T::Chalk: HasInterner<Interner = Interner>,
451 {
452     type Chalk = chalk_ir::Canonical<T::Chalk>;
453
454     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T::Chalk> {
455         let value = self.value.to_chalk(db);
456         chalk_ir::Canonical { value, binders: self.binders }
457     }
458
459     fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {
460         Canonical { binders: canonical.binders, value: from_chalk(db, canonical.value) }
461     }
462 }
463
464 impl<T: ToChalk> ToChalk for InEnvironment<T>
465 where
466     T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>,
467 {
468     type Chalk = chalk_ir::InEnvironment<T::Chalk>;
469
470     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> {
471         chalk_ir::InEnvironment { environment: self.environment, goal: self.goal.to_chalk(db) }
472     }
473
474     fn from_chalk(
475         _db: &dyn HirDatabase,
476         _in_env: chalk_ir::InEnvironment<T::Chalk>,
477     ) -> InEnvironment<T> {
478         unimplemented!()
479     }
480 }
481
482 impl<T: ToChalk> ToChalk for crate::Binders<T>
483 where
484     T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>,
485 {
486     type Chalk = chalk_ir::Binders<T::Chalk>;
487
488     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> {
489         chalk_ir::Binders::new(
490             chalk_ir::VariableKinds::from_iter(
491                 &Interner,
492                 std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
493                     .take(self.num_binders),
494             ),
495             self.value.to_chalk(db),
496         )
497     }
498
499     fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T::Chalk>) -> crate::Binders<T> {
500         let (v, b) = binders.into_value_and_skipped_binders();
501         crate::Binders::new(b.len(&Interner), from_chalk(db, v))
502     }
503 }
504
505 pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T>
506 where
507     T: HasInterner<Interner = Interner>,
508 {
509     chalk_ir::Binders::new(
510         chalk_ir::VariableKinds::from_iter(
511             &Interner,
512             std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
513                 .take(num_vars),
514         ),
515         value,
516     )
517 }
518
519 pub(super) fn convert_where_clauses(
520     db: &dyn HirDatabase,
521     def: GenericDefId,
522     substs: &Substitution,
523 ) -> Vec<chalk_ir::QuantifiedWhereClause<Interner>> {
524     let generic_predicates = db.generic_predicates(def);
525     let mut result = Vec::with_capacity(generic_predicates.len());
526     for pred in generic_predicates.iter() {
527         result.push(pred.clone().subst(substs).to_chalk(db));
528     }
529     result
530 }
531
532 pub(super) fn generic_predicate_to_inline_bound(
533     db: &dyn HirDatabase,
534     pred: &QuantifiedWhereClause,
535     self_ty: &Ty,
536 ) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> {
537     // An InlineBound is like a GenericPredicate, except the self type is left out.
538     // We don't have a special type for this, but Chalk does.
539     let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE);
540     match &pred.value {
541         WhereClause::Implemented(trait_ref) => {
542             if trait_ref.self_type_parameter() != &self_ty_shifted_in {
543                 // we can only convert predicates back to type bounds if they
544                 // have the expected self type
545                 return None;
546             }
547             let args_no_self = trait_ref.substitution.interned()[1..]
548                 .iter()
549                 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
550                 .collect();
551             let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
552             Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders))
553         }
554         WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
555             if projection_ty.self_type_parameter() != &self_ty_shifted_in {
556                 return None;
557             }
558             let trait_ = projection_ty.trait_(db);
559             let args_no_self = projection_ty.substitution.interned()[1..]
560                 .iter()
561                 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
562                 .collect();
563             let alias_eq_bound = rust_ir::AliasEqBound {
564                 value: ty.clone().to_chalk(db),
565                 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
566                 associated_ty_id: projection_ty.associated_ty_id,
567                 parameters: Vec::new(), // FIXME we don't support generic associated types yet
568             };
569             Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), pred.num_binders))
570         }
571         _ => None,
572     }
573 }