diff options
Diffstat (limited to 'crates/ra_hir/src/ty/traits')
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 06388a3ce..78f4b3e27 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 | }; |
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, ContainerId, GenericDefId, Lookup, TypeAliasId}; | 12 | use hir_def::{lang_item::LangItemTarget, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId}; |
13 | use hir_expand::name; | 13 | use hir_expand::name; |
14 | 14 | ||
15 | use ra_db::salsa::{InternId, InternKey}; | 15 | use ra_db::salsa::{InternId, InternKey}; |
@@ -459,7 +459,7 @@ where | |||
459 | [super::FnTrait::FnOnce, super::FnTrait::FnMut, super::FnTrait::Fn].iter() | 459 | [super::FnTrait::FnOnce, super::FnTrait::FnMut, super::FnTrait::Fn].iter() |
460 | { | 460 | { |
461 | if let Some(actual_trait) = get_fn_trait(self.db, self.krate, fn_trait) { | 461 | if let Some(actual_trait) = get_fn_trait(self.db, self.krate, fn_trait) { |
462 | if trait_ == actual_trait { | 462 | if trait_.id == actual_trait { |
463 | let impl_ = super::ClosureFnTraitImplData { def, expr, fn_trait }; | 463 | let impl_ = super::ClosureFnTraitImplData { def, expr, fn_trait }; |
464 | result.push(Impl::ClosureFnTraitImpl(impl_).to_chalk(self.db)); | 464 | result.push(Impl::ClosureFnTraitImpl(impl_).to_chalk(self.db)); |
465 | } | 465 | } |
@@ -661,6 +661,7 @@ fn impl_block_datum( | |||
661 | }; | 661 | }; |
662 | 662 | ||
663 | let impl_datum_bound = chalk_rust_ir::ImplDatumBound { trait_ref, where_clauses }; | 663 | let impl_datum_bound = chalk_rust_ir::ImplDatumBound { trait_ref, where_clauses }; |
664 | let trait_data = db.trait_data(trait_.id); | ||
664 | let associated_ty_value_ids = impl_block | 665 | let associated_ty_value_ids = impl_block |
665 | .items(db) | 666 | .items(db) |
666 | .into_iter() | 667 | .into_iter() |
@@ -670,7 +671,7 @@ fn impl_block_datum( | |||
670 | }) | 671 | }) |
671 | .filter(|type_alias| { | 672 | .filter(|type_alias| { |
672 | // don't include associated types that don't exist in the trait | 673 | // don't include associated types that don't exist in the trait |
673 | trait_.associated_type_by_name(db, &type_alias.name(db)).is_some() | 674 | trait_data.associated_type_by_name(&type_alias.name(db)).is_some() |
674 | }) | 675 | }) |
675 | .map(|type_alias| AssocTyValue::TypeAlias(type_alias).to_chalk(db)) | 676 | .map(|type_alias| AssocTyValue::TypeAlias(type_alias).to_chalk(db)) |
676 | .collect(); | 677 | .collect(); |
@@ -713,7 +714,7 @@ fn closure_fn_trait_impl_datum( | |||
713 | // and don't want to return a valid value only to find out later that FnOnce | 714 | // and don't want to return a valid value only to find out later that FnOnce |
714 | // is broken | 715 | // is broken |
715 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; | 716 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; |
716 | fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?; | 717 | let _output = db.trait_data(fn_once_trait).associated_type_by_name(&name::OUTPUT_TYPE)?; |
717 | 718 | ||
718 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { | 719 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { |
719 | crate::expr::Expr::Lambda { args, .. } => args.len() as u16, | 720 | crate::expr::Expr::Lambda { args, .. } => args.len() as u16, |
@@ -735,8 +736,8 @@ fn closure_fn_trait_impl_datum( | |||
735 | let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); | 736 | let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); |
736 | 737 | ||
737 | let trait_ref = TraitRef { | 738 | let trait_ref = TraitRef { |
738 | trait_, | 739 | trait_: trait_.into(), |
739 | substs: Substs::build_for_def(db, trait_.id).push(self_ty).push(arg_ty).build(), | 740 | substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), |
740 | }; | 741 | }; |
741 | 742 | ||
742 | let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db); | 743 | let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db); |
@@ -783,10 +784,10 @@ fn type_alias_associated_ty_value( | |||
783 | .target_trait_ref(db) | 784 | .target_trait_ref(db) |
784 | .expect("assoc ty value should not exist") // we don't return any assoc ty values if the impl'd trait can't be resolved | 785 | .expect("assoc ty value should not exist") // we don't return any assoc ty values if the impl'd trait can't be resolved |
785 | .trait_; | 786 | .trait_; |
786 | let assoc_ty = trait_ | 787 | let assoc_ty = db |
787 | .associated_type_by_name(db, &type_alias.name(db)) | 788 | .trait_data(trait_.id) |
788 | .expect("assoc ty value should not exist") // validated when building the impl data as well | 789 | .associated_type_by_name(&type_alias.name(db)) |
789 | .id; | 790 | .expect("assoc ty value should not exist"); // validated when building the impl data as well |
790 | let generic_params = db.generic_params(impl_block.id.into()); | 791 | let generic_params = db.generic_params(impl_block.id.into()); |
791 | let bound_vars = Substs::bound_vars(&generic_params); | 792 | let bound_vars = Substs::bound_vars(&generic_params); |
792 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); | 793 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); |
@@ -819,10 +820,10 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
819 | let fn_once_trait = | 820 | let fn_once_trait = |
820 | get_fn_trait(db, krate, super::FnTrait::FnOnce).expect("assoc ty value should not exist"); | 821 | get_fn_trait(db, krate, super::FnTrait::FnOnce).expect("assoc ty value should not exist"); |
821 | 822 | ||
822 | let output_ty_id = fn_once_trait | 823 | let output_ty_id = db |
823 | .associated_type_by_name(db, &name::OUTPUT_TYPE) | 824 | .trait_data(fn_once_trait) |
824 | .expect("assoc ty value should not exist") | 825 | .associated_type_by_name(&name::OUTPUT_TYPE) |
825 | .id; | 826 | .expect("assoc ty value should not exist"); |
826 | 827 | ||
827 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: output_ty.to_chalk(db) }; | 828 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: output_ty.to_chalk(db) }; |
828 | 829 | ||
@@ -834,10 +835,10 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
834 | Arc::new(value) | 835 | Arc::new(value) |
835 | } | 836 | } |
836 | 837 | ||
837 | fn get_fn_trait(db: &impl HirDatabase, krate: Crate, fn_trait: super::FnTrait) -> Option<Trait> { | 838 | fn get_fn_trait(db: &impl HirDatabase, krate: Crate, fn_trait: super::FnTrait) -> Option<TraitId> { |
838 | let target = db.lang_item(krate.crate_id, fn_trait.lang_item_name().into())?; | 839 | let target = db.lang_item(krate.crate_id, fn_trait.lang_item_name().into())?; |
839 | match target { | 840 | match target { |
840 | LangItemTarget::TraitId(t) => Some(t.into()), | 841 | LangItemTarget::TraitId(t) => Some(t), |
841 | _ => None, | 842 | _ => None, |
842 | } | 843 | } |
843 | } | 844 | } |