diff options
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index aef6b8a15..5e4f97a46 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -10,11 +10,9 @@ use base_db::salsa::InternKey; | |||
10 | use hir_def::{GenericDefId, TypeAliasId}; | 10 | use hir_def::{GenericDefId, TypeAliasId}; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | db::HirDatabase, | 13 | db::HirDatabase, primitive::UintTy, AliasTy, CallableDefId, Canonical, DomainGoal, FnPointer, |
14 | primitive::UintTy, | 14 | GenericArg, InEnvironment, OpaqueTy, ProjectionTy, QuantifiedWhereClause, Scalar, Substitution, |
15 | traits::{Canonical, DomainGoal}, | 15 | TraitRef, Ty, TypeWalk, WhereClause, |
16 | AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy, | ||
17 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, | ||
18 | }; | 16 | }; |
19 | 17 | ||
20 | use super::interner::*; | 18 | use super::interner::*; |
@@ -137,7 +135,7 @@ impl ToChalk for Ty { | |||
137 | db, | 135 | db, |
138 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 136 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
139 | ); | 137 | ); |
140 | TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs }) | 138 | TyKind::Function(FnPointer { num_args: (substs.len(&Interner) - 1), sig, substs }) |
141 | } | 139 | } |
142 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), | 140 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), |
143 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, | 141 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, |
@@ -216,25 +214,40 @@ fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> { | |||
216 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) | 214 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) |
217 | } | 215 | } |
218 | 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 | |||
219 | impl ToChalk for Substitution { | 235 | impl ToChalk for Substitution { |
220 | type Chalk = chalk_ir::Substitution<Interner>; | 236 | type Chalk = chalk_ir::Substitution<Interner>; |
221 | 237 | ||
222 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { | 238 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { |
223 | chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) | 239 | chalk_ir::Substitution::from_iter( |
240 | &Interner, | ||
241 | self.iter(&Interner).map(|ty| ty.clone().to_chalk(db)), | ||
242 | ) | ||
224 | } | 243 | } |
225 | 244 | ||
226 | fn from_chalk( | 245 | fn from_chalk( |
227 | db: &dyn HirDatabase, | 246 | db: &dyn HirDatabase, |
228 | parameters: chalk_ir::Substitution<Interner>, | 247 | parameters: chalk_ir::Substitution<Interner>, |
229 | ) -> Substitution { | 248 | ) -> Substitution { |
230 | let tys = parameters | 249 | let tys = parameters.iter(&Interner).map(|p| from_chalk(db, p.clone())).collect(); |
231 | .iter(&Interner) | 250 | Substitution::intern(tys) |
232 | .map(|p| match p.ty(&Interner) { | ||
233 | Some(ty) => from_chalk(db, ty.clone()), | ||
234 | None => unimplemented!(), | ||
235 | }) | ||
236 | .collect(); | ||
237 | Substitution(tys) | ||
238 | } | 251 | } |
239 | } | 252 | } |
240 | 253 | ||
@@ -531,7 +544,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
531 | // have the expected self type | 544 | // have the expected self type |
532 | return None; | 545 | return None; |
533 | } | 546 | } |
534 | let args_no_self = trait_ref.substitution[1..] | 547 | let args_no_self = trait_ref.substitution.interned()[1..] |
535 | .iter() | 548 | .iter() |
536 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 549 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
537 | .collect(); | 550 | .collect(); |
@@ -543,7 +556,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
543 | return None; | 556 | return None; |
544 | } | 557 | } |
545 | let trait_ = projection_ty.trait_(db); | 558 | let trait_ = projection_ty.trait_(db); |
546 | let args_no_self = projection_ty.substitution[1..] | 559 | let args_no_self = projection_ty.substitution.interned()[1..] |
547 | .iter() | 560 | .iter() |
548 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 561 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
549 | .collect(); | 562 | .collect(); |