aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-25 15:58:17 +0000
committerAleksey Kladov <[email protected]>2019-11-25 15:58:17 +0000
commit1a0da6d4dad846568042f85ad7225b45b3275e49 (patch)
tree3fe683f845d7b3b47f44337303dac2ff8312a832 /crates/ra_hir/src/ty
parent6d2ec8765d418b365dfaf472ab9b2b53b8eeafa9 (diff)
Use TypeAliasId in Ty, pt 2
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs2
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs6
-rw-r--r--crates/ra_hir/src/ty/lower.rs9
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs34
4 files changed, 22 insertions, 29 deletions
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index 44547197c..9e7593b8b 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -69,7 +69,7 @@ fn deref_by_trait(
69 69
70 let projection = super::traits::ProjectionPredicate { 70 let projection = super::traits::ProjectionPredicate {
71 ty: Ty::Bound(0), 71 ty: Ty::Bound(0),
72 projection_ty: super::ProjectionTy { associated_ty: target, parameters }, 72 projection_ty: super::ProjectionTy { associated_ty: target.id, parameters },
73 }; 73 };
74 74
75 let obligation = super::Obligation::Projection(projection); 75 let obligation = super::Obligation::Projection(projection);
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index b581d192f..316cdc880 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -101,7 +101,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
101 let projection = ProjectionPredicate { 101 let projection = ProjectionPredicate {
102 ty: pat_ty.clone(), 102 ty: pat_ty.clone(),
103 projection_ty: ProjectionTy { 103 projection_ty: ProjectionTy {
104 associated_ty: into_iter_item_alias, 104 associated_ty: into_iter_item_alias.id,
105 parameters: Substs::single(iterable_ty), 105 parameters: Substs::single(iterable_ty),
106 }, 106 },
107 }; 107 };
@@ -283,7 +283,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
283 let projection = ProjectionPredicate { 283 let projection = ProjectionPredicate {
284 ty: ty.clone(), 284 ty: ty.clone(),
285 projection_ty: ProjectionTy { 285 projection_ty: ProjectionTy {
286 associated_ty: future_future_output_alias, 286 associated_ty: future_future_output_alias.id,
287 parameters: Substs::single(inner_ty), 287 parameters: Substs::single(inner_ty),
288 }, 288 },
289 }; 289 };
@@ -302,7 +302,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
302 let projection = ProjectionPredicate { 302 let projection = ProjectionPredicate {
303 ty: ty.clone(), 303 ty: ty.clone(),
304 projection_ty: ProjectionTy { 304 projection_ty: ProjectionTy {
305 associated_ty: ops_try_ok_alias, 305 associated_ty: ops_try_ok_alias.id,
306 parameters: Substs::single(inner_ty), 306 parameters: Substs::single(inner_ty),
307 }, 307 },
308 }; 308 };
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index eb51d31bd..d7d4bb0d6 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -176,7 +176,7 @@ impl Ty {
176 Some(associated_ty) => { 176 Some(associated_ty) => {
177 // FIXME handle type parameters on the segment 177 // FIXME handle type parameters on the segment
178 Ty::Projection(ProjectionTy { 178 Ty::Projection(ProjectionTy {
179 associated_ty, 179 associated_ty: associated_ty.id,
180 parameters: trait_ref.substs, 180 parameters: trait_ref.substs,
181 }) 181 })
182 } 182 }
@@ -268,7 +268,10 @@ impl Ty {
268 .fill_with_unknown() 268 .fill_with_unknown()
269 .build(); 269 .build();
270 // FIXME handle type parameters on the segment 270 // FIXME handle type parameters on the segment
271 return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); 271 return Ty::Projection(ProjectionTy {
272 associated_ty: associated_ty.id,
273 parameters: substs,
274 });
272 } 275 }
273 } 276 }
274 Ty::Unknown 277 Ty::Unknown
@@ -508,7 +511,7 @@ fn assoc_type_bindings_from_type_bound<'a>(
508 let associated_ty = 511 let associated_ty =
509 match trait_ref.trait_.associated_type_by_name_including_super_traits(db, &name) { 512 match trait_ref.trait_.associated_type_by_name_including_super_traits(db, &name) {
510 None => return GenericPredicate::Error, 513 None => return GenericPredicate::Error,
511 Some(t) => t, 514 Some(t) => t.id,
512 }; 515 };
513 let projection_ty = 516 let projection_ty =
514 ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() }; 517 ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() };
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index fd2f1b174..06388a3ce 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -9,7 +9,7 @@ use chalk_ir::{
9}; 9};
10use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; 10use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
11 11
12use hir_def::{lang_item::LangItemTarget, GenericDefId, TypeAliasId}; 12use hir_def::{lang_item::LangItemTarget, ContainerId, GenericDefId, Lookup, TypeAliasId};
13use hir_expand::name; 13use hir_expand::name;
14 14
15use ra_db::salsa::{InternId, InternKey}; 15use ra_db::salsa::{InternId, InternKey};
@@ -203,18 +203,6 @@ impl ToChalk for Impl {
203 } 203 }
204} 204}
205 205
206impl ToChalk for TypeAlias {
207 type Chalk = chalk_ir::TypeId;
208
209 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId {
210 chalk_ir::TypeId(id_to_chalk(self.id))
211 }
212
213 fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAlias {
214 TypeAlias { id: id_from_chalk(type_alias_id.0) }
215 }
216}
217
218impl ToChalk for TypeAliasId { 206impl ToChalk for TypeAliasId {
219 type Chalk = chalk_ir::TypeId; 207 type Chalk = chalk_ir::TypeId;
220 208
@@ -516,21 +504,21 @@ pub(crate) fn associated_ty_data_query(
516 id: TypeId, 504 id: TypeId,
517) -> Arc<AssociatedTyDatum<ChalkIr>> { 505) -> Arc<AssociatedTyDatum<ChalkIr>> {
518 debug!("associated_ty_data {:?}", id); 506 debug!("associated_ty_data {:?}", id);
519 let type_alias: TypeAlias = from_chalk(db, id); 507 let type_alias: TypeAliasId = from_chalk(db, id);
520 let trait_ = match type_alias.container(db) { 508 let trait_ = match type_alias.lookup(db).container {
521 Some(crate::Container::Trait(t)) => t, 509 ContainerId::TraitId(t) => t,
522 _ => panic!("associated type not in trait"), 510 _ => panic!("associated type not in trait"),
523 }; 511 };
524 let generic_params = db.generic_params(type_alias.id.into()); 512 let generic_params = db.generic_params(type_alias.into());
525 let bound_data = chalk_rust_ir::AssociatedTyDatumBound { 513 let bound_data = chalk_rust_ir::AssociatedTyDatumBound {
526 // FIXME add bounds and where clauses 514 // FIXME add bounds and where clauses
527 bounds: vec![], 515 bounds: vec![],
528 where_clauses: vec![], 516 where_clauses: vec![],
529 }; 517 };
530 let datum = AssociatedTyDatum { 518 let datum = AssociatedTyDatum {
531 trait_id: trait_.to_chalk(db), 519 trait_id: Trait::from(trait_).to_chalk(db),
532 id, 520 id,
533 name: lalrpop_intern::intern(&type_alias.name(db).to_string()), 521 name: lalrpop_intern::intern(&db.type_alias_data(type_alias).name.to_string()),
534 binders: make_binders(bound_data, generic_params.count_params_including_parent()), 522 binders: make_binders(bound_data, generic_params.count_params_including_parent()),
535 }; 523 };
536 Arc::new(datum) 524 Arc::new(datum)
@@ -578,7 +566,7 @@ pub(crate) fn trait_datum_query(
578 .items(db) 566 .items(db)
579 .into_iter() 567 .into_iter()
580 .filter_map(|trait_item| match trait_item { 568 .filter_map(|trait_item| match trait_item {
581 crate::AssocItem::TypeAlias(type_alias) => Some(type_alias), 569 crate::AssocItem::TypeAlias(type_alias) => Some(type_alias.id),
582 _ => None, 570 _ => None,
583 }) 571 })
584 .map(|type_alias| type_alias.to_chalk(db)) 572 .map(|type_alias| type_alias.to_chalk(db))
@@ -797,7 +785,8 @@ fn type_alias_associated_ty_value(
797 .trait_; 785 .trait_;
798 let assoc_ty = trait_ 786 let assoc_ty = trait_
799 .associated_type_by_name(db, &type_alias.name(db)) 787 .associated_type_by_name(db, &type_alias.name(db))
800 .expect("assoc ty value should not exist"); // validated when building the impl data as well 788 .expect("assoc ty value should not exist") // validated when building the impl data as well
789 .id;
801 let generic_params = db.generic_params(impl_block.id.into()); 790 let generic_params = db.generic_params(impl_block.id.into());
802 let bound_vars = Substs::bound_vars(&generic_params); 791 let bound_vars = Substs::bound_vars(&generic_params);
803 let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); 792 let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars);
@@ -832,7 +821,8 @@ fn closure_fn_trait_output_assoc_ty_value(
832 821
833 let output_ty_id = fn_once_trait 822 let output_ty_id = fn_once_trait
834 .associated_type_by_name(db, &name::OUTPUT_TYPE) 823 .associated_type_by_name(db, &name::OUTPUT_TYPE)
835 .expect("assoc ty value should not exist"); 824 .expect("assoc ty value should not exist")
825 .id;
836 826
837 let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: output_ty.to_chalk(db) }; 827 let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: output_ty.to_chalk(db) };
838 828