diff options
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 67e88ebf4..72458f367 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -93,12 +93,13 @@ impl ToChalk for Ty { | |||
93 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | 93 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
94 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), | 94 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
95 | TyKind::Dyn(dyn_ty) => { | 95 | TyKind::Dyn(dyn_ty) => { |
96 | let (bounds, binders) = dyn_ty.bounds.into_value_and_skipped_binders(); | ||
96 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( | 97 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
97 | &Interner, | 98 | &Interner, |
98 | dyn_ty.bounds.value.interned().iter().cloned().map(|p| p.to_chalk(db)), | 99 | bounds.interned().iter().cloned().map(|p| p.to_chalk(db)), |
99 | ); | 100 | ); |
100 | let bounded_ty = chalk_ir::DynTy { | 101 | let bounded_ty = chalk_ir::DynTy { |
101 | bounds: make_binders(where_clauses, 1), | 102 | bounds: make_binders(where_clauses, binders), |
102 | lifetime: LifetimeData::Static.intern(&Interner), | 103 | lifetime: LifetimeData::Static.intern(&Interner), |
103 | }; | 104 | }; |
104 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 105 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
@@ -486,13 +487,14 @@ where | |||
486 | type Chalk = chalk_ir::Binders<T::Chalk>; | 487 | type Chalk = chalk_ir::Binders<T::Chalk>; |
487 | 488 | ||
488 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> { | 489 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> { |
490 | let (value, binders) = self.into_value_and_skipped_binders(); | ||
489 | chalk_ir::Binders::new( | 491 | chalk_ir::Binders::new( |
490 | chalk_ir::VariableKinds::from_iter( | 492 | chalk_ir::VariableKinds::from_iter( |
491 | &Interner, | 493 | &Interner, |
492 | std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)) | 494 | std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)) |
493 | .take(self.num_binders), | 495 | .take(binders), |
494 | ), | 496 | ), |
495 | self.value.to_chalk(db), | 497 | value.to_chalk(db), |
496 | ) | 498 | ) |
497 | } | 499 | } |
498 | 500 | ||
@@ -537,7 +539,8 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
537 | // An InlineBound is like a GenericPredicate, except the self type is left out. | 539 | // 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. | 540 | // 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); | 541 | let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE); |
540 | match &pred.value { | 542 | let (pred, binders) = pred.as_ref().into_value_and_skipped_binders(); |
543 | match pred { | ||
541 | WhereClause::Implemented(trait_ref) => { | 544 | WhereClause::Implemented(trait_ref) => { |
542 | if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { | 545 | if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { |
543 | // we can only convert predicates back to type bounds if they | 546 | // we can only convert predicates back to type bounds if they |
@@ -549,7 +552,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
549 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 552 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
550 | .collect(); | 553 | .collect(); |
551 | let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; | 554 | 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)) | 555 | Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), binders)) |
553 | } | 556 | } |
554 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { | 557 | WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { |
555 | if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { | 558 | if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { |
@@ -566,7 +569,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
566 | associated_ty_id: projection_ty.associated_ty_id, | 569 | associated_ty_id: projection_ty.associated_ty_id, |
567 | parameters: Vec::new(), // FIXME we don't support generic associated types yet | 570 | parameters: Vec::new(), // FIXME we don't support generic associated types yet |
568 | }; | 571 | }; |
569 | Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), pred.num_binders)) | 572 | Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), binders)) |
570 | } | 573 | } |
571 | _ => None, | 574 | _ => None, |
572 | } | 575 | } |