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.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 67e88ebf4..c3b148cab 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: chalk_ir::Binders::new(binders, where_clauses),
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)
@@ -148,7 +149,7 @@ impl ToChalk for Ty {
148 .map(|c| from_chalk(db, c.clone())); 149 .map(|c| from_chalk(db, c.clone()));
149 TyKind::Dyn(crate::DynTy { 150 TyKind::Dyn(crate::DynTy {
150 bounds: crate::Binders::new( 151 bounds: crate::Binders::new(
151 1, 152 where_clauses.bounds.binders.clone(),
152 crate::QuantifiedWhereClauses::from_iter(&Interner, bounds), 153 crate::QuantifiedWhereClauses::from_iter(&Interner, bounds),
153 ), 154 ),
154 }) 155 })
@@ -486,19 +487,13 @@ 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> {
489 chalk_ir::Binders::new( 490 let (value, binders) = self.into_value_and_skipped_binders();
490 chalk_ir::VariableKinds::from_iter( 491 chalk_ir::Binders::new(binders, value.to_chalk(db))
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 } 492 }
498 493
499 fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T::Chalk>) -> crate::Binders<T> { 494 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(); 495 let (v, b) = binders.into_value_and_skipped_binders();
501 crate::Binders::new(b.len(&Interner), from_chalk(db, v)) 496 crate::Binders::new(b, from_chalk(db, v))
502 } 497 }
503} 498}
504 499
@@ -524,7 +519,7 @@ pub(super) fn convert_where_clauses(
524 let generic_predicates = db.generic_predicates(def); 519 let generic_predicates = db.generic_predicates(def);
525 let mut result = Vec::with_capacity(generic_predicates.len()); 520 let mut result = Vec::with_capacity(generic_predicates.len());
526 for pred in generic_predicates.iter() { 521 for pred in generic_predicates.iter() {
527 result.push(pred.clone().subst(substs).to_chalk(db)); 522 result.push(pred.clone().substitute(&Interner, substs).to_chalk(db));
528 } 523 }
529 result 524 result
530} 525}
@@ -536,8 +531,9 @@ pub(super) fn generic_predicate_to_inline_bound(
536) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> { 531) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> {
537 // An InlineBound is like a GenericPredicate, except the self type is left out. 532 // 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. 533 // 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); 534 let self_ty_shifted_in = self_ty.clone().shifted_in_from(DebruijnIndex::ONE);
540 match &pred.value { 535 let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
536 match pred {
541 WhereClause::Implemented(trait_ref) => { 537 WhereClause::Implemented(trait_ref) => {
542 if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { 538 if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in {
543 // we can only convert predicates back to type bounds if they 539 // we can only convert predicates back to type bounds if they
@@ -549,7 +545,7 @@ pub(super) fn generic_predicate_to_inline_bound(
549 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 545 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
550 .collect(); 546 .collect();
551 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; 547 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)) 548 Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
553 } 549 }
554 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 550 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
555 if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { 551 if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in {
@@ -566,7 +562,10 @@ pub(super) fn generic_predicate_to_inline_bound(
566 associated_ty_id: projection_ty.associated_ty_id, 562 associated_ty_id: projection_ty.associated_ty_id,
567 parameters: Vec::new(), // FIXME we don't support generic associated types yet 563 parameters: Vec::new(), // FIXME we don't support generic associated types yet
568 }; 564 };
569 Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), pred.num_binders)) 565 Some(chalk_ir::Binders::new(
566 binders,
567 rust_ir::InlineBound::AliasEqBound(alias_eq_bound),
568 ))
570 } 569 }
571 _ => None, 570 _ => None,
572 } 571 }