aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk.rs')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs47
1 files changed, 24 insertions, 23 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}