aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs47
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs33
2 files changed, 40 insertions, 40 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index b7388b98c..dff87ef70 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -184,16 +184,21 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
184 .db 184 .db
185 .return_type_impl_traits(func) 185 .return_type_impl_traits(func)
186 .expect("impl trait id without impl traits"); 186 .expect("impl trait id without impl traits");
187 let data = &datas.value.impl_traits[idx as usize]; 187 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
188 let data = &datas.impl_traits[idx as usize];
188 let bound = OpaqueTyDatumBound { 189 let bound = OpaqueTyDatumBound {
189 bounds: make_binders( 190 bounds: make_binders(
190 data.bounds.value.iter().cloned().map(|b| b.to_chalk(self.db)).collect(), 191 data.bounds
192 .skip_binders()
193 .iter()
194 .cloned()
195 .map(|b| b.to_chalk(self.db))
196 .collect(),
191 1, 197 1,
192 ), 198 ),
193 where_clauses: make_binders(vec![], 0), 199 where_clauses: make_binders(vec![], 0),
194 }; 200 };
195 let num_vars = datas.num_binders; 201 chalk_ir::Binders::new(binders, bound)
196 make_binders(bound, num_vars)
197 } 202 }
198 crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => { 203 crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => {
199 if let Some((future_trait, future_output)) = self 204 if let Some((future_trait, future_output)) = self
@@ -535,7 +540,8 @@ fn impl_def_datum(
535 .impl_trait(impl_id) 540 .impl_trait(impl_id)
536 // ImplIds for impls where the trait ref can't be resolved should never reach Chalk 541 // ImplIds for impls where the trait ref can't be resolved should never reach Chalk
537 .expect("invalid impl passed to Chalk") 542 .expect("invalid impl passed to Chalk")
538 .value; 543 .into_value_and_skipped_binders()
544 .0;
539 let impl_data = db.impl_data(impl_id); 545 let impl_data = db.impl_data(impl_id);
540 546
541 let generic_params = generics(db.upcast(), impl_id.into()); 547 let generic_params = generics(db.upcast(), impl_id.into());
@@ -605,18 +611,22 @@ fn type_alias_associated_ty_value(
605 _ => panic!("assoc ty value should be in impl"), 611 _ => panic!("assoc ty value should be in impl"),
606 }; 612 };
607 613
608 let trait_ref = db.impl_trait(impl_id).expect("assoc ty value should not exist").value; // we don't return any assoc ty values if the impl'd trait can't be resolved 614 let trait_ref = db
615 .impl_trait(impl_id)
616 .expect("assoc ty value should not exist")
617 .into_value_and_skipped_binders()
618 .0; // we don't return any assoc ty values if the impl'd trait can't be resolved
609 619
610 let assoc_ty = db 620 let assoc_ty = db
611 .trait_data(trait_ref.hir_trait_id()) 621 .trait_data(trait_ref.hir_trait_id())
612 .associated_type_by_name(&type_alias_data.name) 622 .associated_type_by_name(&type_alias_data.name)
613 .expect("assoc ty value should not exist"); // validated when building the impl data as well 623 .expect("assoc ty value should not exist"); // validated when building the impl data as well
614 let ty = db.ty(type_alias.into()); 624 let (ty, binders) = db.ty(type_alias.into()).into_value_and_skipped_binders();
615 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; 625 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) };
616 let value = rust_ir::AssociatedTyValue { 626 let value = rust_ir::AssociatedTyValue {
617 impl_id: impl_id.to_chalk(db), 627 impl_id: impl_id.to_chalk(db),
618 associated_ty_id: to_assoc_type_id(assoc_ty), 628 associated_ty_id: to_assoc_type_id(assoc_ty),
619 value: make_binders(value_bound, ty.num_binders), 629 value: chalk_ir::Binders::new(binders, value_bound),
620 }; 630 };
621 Arc::new(value) 631 Arc::new(value)
622} 632}
@@ -628,20 +638,15 @@ pub(crate) fn fn_def_datum_query(
628) -> Arc<FnDefDatum> { 638) -> Arc<FnDefDatum> {
629 let callable_def: CallableDefId = from_chalk(db, fn_def_id); 639 let callable_def: CallableDefId = from_chalk(db, fn_def_id);
630 let generic_params = generics(db.upcast(), callable_def.into()); 640 let generic_params = generics(db.upcast(), callable_def.into());
631 let sig = db.callable_item_signature(callable_def); 641 let (sig, binders) = db.callable_item_signature(callable_def).into_value_and_skipped_binders();
632 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); 642 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
633 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); 643 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars);
634 let bound = rust_ir::FnDefDatumBound { 644 let bound = rust_ir::FnDefDatumBound {
635 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway 645 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway
636 inputs_and_output: make_binders( 646 inputs_and_output: make_binders(
637 rust_ir::FnDefInputsAndOutputDatum { 647 rust_ir::FnDefInputsAndOutputDatum {
638 argument_types: sig 648 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(),
639 .value 649 return_type: sig.ret().clone().to_chalk(db),
640 .params()
641 .iter()
642 .map(|ty| ty.clone().to_chalk(db))
643 .collect(),
644 return_type: sig.value.ret().clone().to_chalk(db),
645 } 650 }
646 .shifted_in(&Interner), 651 .shifted_in(&Interner),
647 0, 652 0,
@@ -650,12 +655,8 @@ pub(crate) fn fn_def_datum_query(
650 }; 655 };
651 let datum = FnDefDatum { 656 let datum = FnDefDatum {
652 id: fn_def_id, 657 id: fn_def_id,
653 sig: chalk_ir::FnSig { 658 sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: sig.is_varargs },
654 abi: (), 659 binders: chalk_ir::Binders::new(binders, bound),
655 safety: chalk_ir::Safety::Safe,
656 variadic: sig.value.is_varargs,
657 },
658 binders: make_binders(bound, sig.num_binders),
659 }; 660 };
660 Arc::new(datum) 661 Arc::new(datum)
661} 662}
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 }