aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits/chalk.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-04-05 17:24:18 +0100
committerFlorian Diebold <[email protected]>2020-04-05 18:23:18 +0100
commit952714685a7c0e0a1c9970839ce307806adaa176 (patch)
tree2d002aa05d91133886bb592ba79e4c9238e37343 /crates/ra_hir_ty/src/traits/chalk.rs
parent3659502816134b45448799acf428055e40fdf4fc (diff)
Upgrade Chalk again
The big change here is counting binders, not variables (https://github.com/rust-lang/chalk/pull/360). We have to adapt to the same scheme for our `Ty::Bound`. It's mostly fine though, even makes some things more clear.
Diffstat (limited to 'crates/ra_hir_ty/src/traits/chalk.rs')
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index ab4cb33b4..53ce362ea 100644
--- a/crates/ra_hir_ty/src/traits/chalk.rs
+++ b/crates/ra_hir_ty/src/traits/chalk.rs
@@ -3,7 +3,10 @@ use std::{fmt, sync::Arc};
3 3
4use log::debug; 4use log::debug;
5 5
6use chalk_ir::{cast::Cast, Goal, GoalData, Parameter, PlaceholderIndex, TypeName, UniverseIndex}; 6use chalk_ir::{
7 cast::Cast, fold::shift::Shift, Goal, GoalData, Parameter, PlaceholderIndex, TypeName,
8 UniverseIndex,
9};
7 10
8use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId}; 11use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId};
9use ra_db::{ 12use ra_db::{
@@ -235,7 +238,7 @@ impl ToChalk for Ty {
235 } 238 }
236 .to_ty::<Interner>(&Interner) 239 .to_ty::<Interner>(&Interner)
237 } 240 }
238 Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(&Interner), 241 Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner),
239 Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), 242 Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
240 Ty::Dyn(predicates) => { 243 Ty::Dyn(predicates) => {
241 let where_clauses = predicates 244 let where_clauses = predicates
@@ -277,7 +280,7 @@ impl ToChalk for Ty {
277 Ty::Projection(ProjectionTy { associated_ty, parameters }) 280 Ty::Projection(ProjectionTy { associated_ty, parameters })
278 } 281 }
279 chalk_ir::TyData::Function(_) => unimplemented!(), 282 chalk_ir::TyData::Function(_) => unimplemented!(),
280 chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32), 283 chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx),
281 chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, 284 chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown,
282 chalk_ir::TyData::Dyn(where_clauses) => { 285 chalk_ir::TyData::Dyn(where_clauses) => {
283 assert_eq!(where_clauses.bounds.binders.len(), 1); 286 assert_eq!(where_clauses.bounds.binders.len(), 1);
@@ -407,15 +410,15 @@ impl ToChalk for GenericPredicate {
407 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { 410 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> {
408 match self { 411 match self {
409 GenericPredicate::Implemented(trait_ref) => { 412 GenericPredicate::Implemented(trait_ref) => {
410 make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0) 413 let chalk_trait_ref = trait_ref.to_chalk(db);
414 let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner);
415 make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0)
416 }
417 GenericPredicate::Projection(projection_pred) => {
418 let ty = projection_pred.ty.to_chalk(db).shifted_in(&Interner);
419 let alias = projection_pred.projection_ty.to_chalk(db).shifted_in(&Interner);
420 make_binders(chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq { alias, ty }), 0)
411 } 421 }
412 GenericPredicate::Projection(projection_pred) => make_binders(
413 chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
414 alias: projection_pred.projection_ty.to_chalk(db),
415 ty: projection_pred.ty.to_chalk(db),
416 }),
417 0,
418 ),
419 GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"), 422 GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"),
420 } 423 }
421 } 424 }
@@ -579,7 +582,8 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData {
579 type Chalk = AssociatedTyValue; 582 type Chalk = AssociatedTyValue;
580 583
581 fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { 584 fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue {
582 let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: self.value.to_chalk(db) }; 585 let ty = self.value.to_chalk(db);
586 let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty };
583 587
584 chalk_rust_ir::AssociatedTyValue { 588 chalk_rust_ir::AssociatedTyValue {
585 associated_ty_id: self.assoc_ty_id.to_chalk(db), 589 associated_ty_id: self.assoc_ty_id.to_chalk(db),
@@ -738,11 +742,13 @@ pub(crate) fn trait_datum_query(
738 let associated_ty_ids = 742 let associated_ty_ids =
739 trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect(); 743 trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect();
740 let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses }; 744 let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses };
745 let well_known = None; // FIXME set this (depending on lang items)
741 let trait_datum = TraitDatum { 746 let trait_datum = TraitDatum {
742 id: trait_id, 747 id: trait_id,
743 binders: make_binders(trait_datum_bound, bound_vars.len()), 748 binders: make_binders(trait_datum_bound, bound_vars.len()),
744 flags, 749 flags,
745 associated_ty_ids, 750 associated_ty_ids,
751 well_known,
746 }; 752 };
747 Arc::new(trait_datum) 753 Arc::new(trait_datum)
748} 754}