diff options
Diffstat (limited to 'crates/ra_hir/src/ty/traits/chalk.rs')
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 9bf93981a..0272dd9ae 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -9,6 +9,7 @@ use chalk_ir::{ | |||
9 | }; | 9 | }; |
10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; | 10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; |
11 | 11 | ||
12 | use hir_def::{lang_item::LangItemTarget, GenericDefId}; | ||
12 | use hir_expand::name; | 13 | use hir_expand::name; |
13 | 14 | ||
14 | use ra_db::salsa::{InternId, InternKey}; | 15 | use ra_db::salsa::{InternId, InternKey}; |
@@ -16,10 +17,9 @@ use ra_db::salsa::{InternId, InternKey}; | |||
16 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; | 17 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; |
17 | use crate::{ | 18 | use crate::{ |
18 | db::HirDatabase, | 19 | db::HirDatabase, |
19 | generics::{GenericDef, HasGenericParams}, | ||
20 | ty::display::HirDisplay, | 20 | ty::display::HirDisplay, |
21 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, | 21 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, |
22 | Crate, HasBody, ImplBlock, Trait, TypeAlias, | 22 | Crate, ImplBlock, Trait, TypeAlias, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | /// This represents a trait whose name we could not resolve. | 25 | /// This represents a trait whose name we could not resolve. |
@@ -402,7 +402,7 @@ fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> { | |||
402 | 402 | ||
403 | fn convert_where_clauses( | 403 | fn convert_where_clauses( |
404 | db: &impl HirDatabase, | 404 | db: &impl HirDatabase, |
405 | def: GenericDef, | 405 | def: GenericDefId, |
406 | substs: &Substs, | 406 | substs: &Substs, |
407 | ) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> { | 407 | ) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> { |
408 | let generic_predicates = db.generic_predicates(def); | 408 | let generic_predicates = db.generic_predicates(def); |
@@ -509,7 +509,7 @@ pub(crate) fn associated_ty_data_query( | |||
509 | Some(crate::Container::Trait(t)) => t, | 509 | Some(crate::Container::Trait(t)) => t, |
510 | _ => panic!("associated type not in trait"), | 510 | _ => panic!("associated type not in trait"), |
511 | }; | 511 | }; |
512 | let generic_params = type_alias.generic_params(db); | 512 | let generic_params = db.generic_params(type_alias.id.into()); |
513 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { | 513 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { |
514 | // FIXME add bounds and where clauses | 514 | // FIXME add bounds and where clauses |
515 | bounds: vec![], | 515 | bounds: vec![], |
@@ -550,7 +550,7 @@ pub(crate) fn trait_datum_query( | |||
550 | } | 550 | } |
551 | let trait_: Trait = from_chalk(db, trait_id); | 551 | let trait_: Trait = from_chalk(db, trait_id); |
552 | debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); | 552 | debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); |
553 | let generic_params = trait_.generic_params(db); | 553 | let generic_params = db.generic_params(trait_.id.into()); |
554 | let bound_vars = Substs::bound_vars(&generic_params); | 554 | let bound_vars = Substs::bound_vars(&generic_params); |
555 | let flags = chalk_rust_ir::TraitFlags { | 555 | let flags = chalk_rust_ir::TraitFlags { |
556 | auto: trait_.is_auto(db), | 556 | auto: trait_.is_auto(db), |
@@ -561,7 +561,7 @@ pub(crate) fn trait_datum_query( | |||
561 | marker: false, | 561 | marker: false, |
562 | fundamental: false, | 562 | fundamental: false, |
563 | }; | 563 | }; |
564 | let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); | 564 | let where_clauses = convert_where_clauses(db, trait_.id.into(), &bound_vars); |
565 | let associated_ty_ids = trait_ | 565 | let associated_ty_ids = trait_ |
566 | .items(db) | 566 | .items(db) |
567 | .into_iter() | 567 | .into_iter() |
@@ -594,7 +594,7 @@ pub(crate) fn struct_datum_query( | |||
594 | let where_clauses = type_ctor | 594 | let where_clauses = type_ctor |
595 | .as_generic_def() | 595 | .as_generic_def() |
596 | .map(|generic_def| { | 596 | .map(|generic_def| { |
597 | let generic_params = generic_def.generic_params(db); | 597 | let generic_params = db.generic_params(generic_def.into()); |
598 | let bound_vars = Substs::bound_vars(&generic_params); | 598 | let bound_vars = Substs::bound_vars(&generic_params); |
599 | convert_where_clauses(db, generic_def, &bound_vars) | 599 | convert_where_clauses(db, generic_def, &bound_vars) |
600 | }) | 600 | }) |
@@ -634,7 +634,7 @@ fn impl_block_datum( | |||
634 | impl_id: ImplId, | 634 | impl_id: ImplId, |
635 | impl_block: ImplBlock, | 635 | impl_block: ImplBlock, |
636 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 636 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { |
637 | let generic_params = impl_block.generic_params(db); | 637 | let generic_params = db.generic_params(impl_block.id.into()); |
638 | let bound_vars = Substs::bound_vars(&generic_params); | 638 | let bound_vars = Substs::bound_vars(&generic_params); |
639 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); | 639 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); |
640 | let trait_ = trait_ref.trait_; | 640 | let trait_ = trait_ref.trait_; |
@@ -643,7 +643,7 @@ fn impl_block_datum( | |||
643 | } else { | 643 | } else { |
644 | chalk_rust_ir::ImplType::External | 644 | chalk_rust_ir::ImplType::External |
645 | }; | 645 | }; |
646 | let where_clauses = convert_where_clauses(db, impl_block.into(), &bound_vars); | 646 | let where_clauses = convert_where_clauses(db, impl_block.id.into(), &bound_vars); |
647 | let negative = impl_block.is_negative(db); | 647 | let negative = impl_block.is_negative(db); |
648 | debug!( | 648 | debug!( |
649 | "impl {:?}: {}{} where {:?}", | 649 | "impl {:?}: {}{} where {:?}", |
@@ -715,7 +715,7 @@ fn closure_fn_trait_impl_datum( | |||
715 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; | 715 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; |
716 | fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?; | 716 | fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?; |
717 | 717 | ||
718 | let num_args: u16 = match &data.def.body(db)[data.expr] { | 718 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { |
719 | crate::expr::Expr::Lambda { args, .. } => args.len() as u16, | 719 | crate::expr::Expr::Lambda { args, .. } => args.len() as u16, |
720 | _ => { | 720 | _ => { |
721 | log::warn!("closure for closure type {:?} not found", data); | 721 | log::warn!("closure for closure type {:?} not found", data); |
@@ -736,7 +736,7 @@ fn closure_fn_trait_impl_datum( | |||
736 | 736 | ||
737 | let trait_ref = TraitRef { | 737 | let trait_ref = TraitRef { |
738 | trait_, | 738 | trait_, |
739 | substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), | 739 | substs: Substs::build_for_def(db, trait_.id).push(self_ty).push(arg_ty).build(), |
740 | }; | 740 | }; |
741 | 741 | ||
742 | let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db); | 742 | let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db); |
@@ -786,7 +786,7 @@ fn type_alias_associated_ty_value( | |||
786 | let assoc_ty = trait_ | 786 | let assoc_ty = trait_ |
787 | .associated_type_by_name(db, &type_alias.name(db)) | 787 | .associated_type_by_name(db, &type_alias.name(db)) |
788 | .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 | let generic_params = impl_block.generic_params(db); | 789 | let generic_params = db.generic_params(impl_block.id.into()); |
790 | let bound_vars = Substs::bound_vars(&generic_params); | 790 | let bound_vars = Substs::bound_vars(&generic_params); |
791 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); | 791 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); |
792 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; | 792 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; |
@@ -805,7 +805,7 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
805 | ) -> Arc<AssociatedTyValue<ChalkIr>> { | 805 | ) -> Arc<AssociatedTyValue<ChalkIr>> { |
806 | let impl_id = Impl::ClosureFnTraitImpl(data.clone()).to_chalk(db); | 806 | let impl_id = Impl::ClosureFnTraitImpl(data.clone()).to_chalk(db); |
807 | 807 | ||
808 | let num_args: u16 = match &data.def.body(db)[data.expr] { | 808 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { |
809 | crate::expr::Expr::Lambda { args, .. } => args.len() as u16, | 809 | crate::expr::Expr::Lambda { args, .. } => args.len() as u16, |
810 | _ => { | 810 | _ => { |
811 | log::warn!("closure for closure type {:?} not found", data); | 811 | log::warn!("closure for closure type {:?} not found", data); |
@@ -833,9 +833,9 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
833 | } | 833 | } |
834 | 834 | ||
835 | fn get_fn_trait(db: &impl HirDatabase, krate: Crate, fn_trait: super::FnTrait) -> Option<Trait> { | 835 | fn get_fn_trait(db: &impl HirDatabase, krate: Crate, fn_trait: super::FnTrait) -> Option<Trait> { |
836 | let target = db.lang_item(krate, fn_trait.lang_item_name().into())?; | 836 | let target = db.lang_item(krate.crate_id, fn_trait.lang_item_name().into())?; |
837 | match target { | 837 | match target { |
838 | crate::lang_item::LangItemTarget::Trait(t) => Some(t), | 838 | LangItemTarget::TraitId(t) => Some(t.into()), |
839 | _ => None, | 839 | _ => None, |
840 | } | 840 | } |
841 | } | 841 | } |
@@ -847,38 +847,38 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId { | |||
847 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } | 847 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } |
848 | } | 848 | } |
849 | 849 | ||
850 | impl From<chalk_ir::StructId> for crate::ids::TypeCtorId { | 850 | impl From<chalk_ir::StructId> for crate::ty::TypeCtorId { |
851 | fn from(struct_id: chalk_ir::StructId) -> Self { | 851 | fn from(struct_id: chalk_ir::StructId) -> Self { |
852 | id_from_chalk(struct_id.0) | 852 | id_from_chalk(struct_id.0) |
853 | } | 853 | } |
854 | } | 854 | } |
855 | 855 | ||
856 | impl From<crate::ids::TypeCtorId> for chalk_ir::StructId { | 856 | impl From<crate::ty::TypeCtorId> for chalk_ir::StructId { |
857 | fn from(type_ctor_id: crate::ids::TypeCtorId) -> Self { | 857 | fn from(type_ctor_id: crate::ty::TypeCtorId) -> Self { |
858 | chalk_ir::StructId(id_to_chalk(type_ctor_id)) | 858 | chalk_ir::StructId(id_to_chalk(type_ctor_id)) |
859 | } | 859 | } |
860 | } | 860 | } |
861 | 861 | ||
862 | impl From<chalk_ir::ImplId> for crate::ids::GlobalImplId { | 862 | impl From<chalk_ir::ImplId> for crate::ty::traits::GlobalImplId { |
863 | fn from(impl_id: chalk_ir::ImplId) -> Self { | 863 | fn from(impl_id: chalk_ir::ImplId) -> Self { |
864 | id_from_chalk(impl_id.0) | 864 | id_from_chalk(impl_id.0) |
865 | } | 865 | } |
866 | } | 866 | } |
867 | 867 | ||
868 | impl From<crate::ids::GlobalImplId> for chalk_ir::ImplId { | 868 | impl From<crate::ty::traits::GlobalImplId> for chalk_ir::ImplId { |
869 | fn from(impl_id: crate::ids::GlobalImplId) -> Self { | 869 | fn from(impl_id: crate::ty::traits::GlobalImplId) -> Self { |
870 | chalk_ir::ImplId(id_to_chalk(impl_id)) | 870 | chalk_ir::ImplId(id_to_chalk(impl_id)) |
871 | } | 871 | } |
872 | } | 872 | } |
873 | 873 | ||
874 | impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ids::AssocTyValueId { | 874 | impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ty::traits::AssocTyValueId { |
875 | fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { | 875 | fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { |
876 | id_from_chalk(id.0) | 876 | id_from_chalk(id.0) |
877 | } | 877 | } |
878 | } | 878 | } |
879 | 879 | ||
880 | impl From<crate::ids::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId { | 880 | impl From<crate::ty::traits::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId { |
881 | fn from(assoc_ty_value_id: crate::ids::AssocTyValueId) -> Self { | 881 | fn from(assoc_ty_value_id: crate::ty::traits::AssocTyValueId) -> Self { |
882 | chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id)) | 882 | chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id)) |
883 | } | 883 | } |
884 | } | 884 | } |