diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-03 10:19:55 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-03 10:19:55 +0100 |
commit | 8289b96216b5d4ddd0b6cf9feccb7af574d022a8 (patch) | |
tree | 079dabc4e0de72e30d2bd04bd50427ff6950b348 /crates/hir_ty/src/traits/chalk | |
parent | 327f3a0a3017e047be58b8312f8bf3ac690db3fd (diff) | |
parent | e480d81988fc0c0e4f80f1c54058b95b9aaf1ebf (diff) |
Merge #8309
8309: Introduce `GenericArg` like in Chalk r=flodiebold a=flodiebold
Plus some more adaptations to Substitution.
Lots of `assert_ty_ref` that we should revisit when introducing lifetime/const parameters.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index aef6b8a15..452b357e8 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -13,7 +13,7 @@ use crate::{ | |||
13 | db::HirDatabase, | 13 | db::HirDatabase, |
14 | primitive::UintTy, | 14 | primitive::UintTy, |
15 | traits::{Canonical, DomainGoal}, | 15 | traits::{Canonical, DomainGoal}, |
16 | AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy, | 16 | AliasTy, CallableDefId, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, |
17 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, | 17 | QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause, |
18 | }; | 18 | }; |
19 | 19 | ||
@@ -137,7 +137,7 @@ impl ToChalk for Ty { | |||
137 | db, | 137 | db, |
138 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 138 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
139 | ); | 139 | ); |
140 | TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs }) | 140 | TyKind::Function(FnPointer { num_args: (substs.len(&Interner) - 1), sig, substs }) |
141 | } | 141 | } |
142 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), | 142 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), |
143 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, | 143 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, |
@@ -216,24 +216,39 @@ fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> { | |||
216 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) | 216 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) |
217 | } | 217 | } |
218 | 218 | ||
219 | impl ToChalk for GenericArg { | ||
220 | type Chalk = chalk_ir::GenericArg<Interner>; | ||
221 | |||
222 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk { | ||
223 | match self.interned { | ||
224 | crate::GenericArgData::Ty(ty) => ty.to_chalk(db).cast(&Interner), | ||
225 | } | ||
226 | } | ||
227 | |||
228 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { | ||
229 | match chalk.interned() { | ||
230 | chalk_ir::GenericArgData::Ty(ty) => Ty::from_chalk(db, ty.clone()).cast(&Interner), | ||
231 | chalk_ir::GenericArgData::Lifetime(_) => unimplemented!(), | ||
232 | chalk_ir::GenericArgData::Const(_) => unimplemented!(), | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
219 | impl ToChalk for Substitution { | 237 | impl ToChalk for Substitution { |
220 | type Chalk = chalk_ir::Substitution<Interner>; | 238 | type Chalk = chalk_ir::Substitution<Interner>; |
221 | 239 | ||
222 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { | 240 | 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))) | 241 | chalk_ir::Substitution::from_iter( |
242 | &Interner, | ||
243 | self.iter(&Interner).map(|ty| ty.clone().to_chalk(db)), | ||
244 | ) | ||
224 | } | 245 | } |
225 | 246 | ||
226 | fn from_chalk( | 247 | fn from_chalk( |
227 | db: &dyn HirDatabase, | 248 | db: &dyn HirDatabase, |
228 | parameters: chalk_ir::Substitution<Interner>, | 249 | parameters: chalk_ir::Substitution<Interner>, |
229 | ) -> Substitution { | 250 | ) -> Substitution { |
230 | let tys = parameters | 251 | let tys = parameters.iter(&Interner).map(|p| from_chalk(db, p.clone())).collect(); |
231 | .iter(&Interner) | ||
232 | .map(|p| match p.ty(&Interner) { | ||
233 | Some(ty) => from_chalk(db, ty.clone()), | ||
234 | None => unimplemented!(), | ||
235 | }) | ||
236 | .collect(); | ||
237 | Substitution(tys) | 252 | Substitution(tys) |
238 | } | 253 | } |
239 | } | 254 | } |
@@ -531,7 +546,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
531 | // have the expected self type | 546 | // have the expected self type |
532 | return None; | 547 | return None; |
533 | } | 548 | } |
534 | let args_no_self = trait_ref.substitution[1..] | 549 | let args_no_self = trait_ref.substitution.interned(&Interner)[1..] |
535 | .iter() | 550 | .iter() |
536 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 551 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
537 | .collect(); | 552 | .collect(); |
@@ -543,7 +558,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
543 | return None; | 558 | return None; |
544 | } | 559 | } |
545 | let trait_ = projection_ty.trait_(db); | 560 | let trait_ = projection_ty.trait_(db); |
546 | let args_no_self = projection_ty.substitution[1..] | 561 | let args_no_self = projection_ty.substitution.interned(&Interner)[1..] |
547 | .iter() | 562 | .iter() |
548 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 563 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
549 | .collect(); | 564 | .collect(); |