diff options
Diffstat (limited to 'crates/ra_hir/src/ty/traits/chalk.rs')
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 7b2e530a2..67ac5422c 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -4,15 +4,15 @@ use std::sync::Arc; | |||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{ |
7 | cast::Cast, family::ChalkIr, Identifier, ImplId, Parameter, PlaceholderIndex, TypeId, | 7 | cast::Cast, family::ChalkIr, Identifier, Parameter, PlaceholderIndex, TypeId, TypeKindId, |
8 | TypeKindId, TypeName, UniverseIndex, | 8 | TypeName, UniverseIndex, |
9 | }; | 9 | }; |
10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; | 10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; |
11 | use ra_db::CrateId; | 11 | use ra_db::CrateId; |
12 | 12 | ||
13 | use hir_def::{ | 13 | use hir_def::{ |
14 | lang_item::LangItemTarget, resolver::HasResolver, AstItemDef, ContainerId, GenericDefId, | 14 | lang_item::LangItemTarget, resolver::HasResolver, AssocItemId, AstItemDef, ContainerId, |
15 | Lookup, TraitId, TypeAliasId, | 15 | GenericDefId, ImplId, Lookup, TraitId, TypeAliasId, |
16 | }; | 16 | }; |
17 | use hir_expand::name; | 17 | use hir_expand::name; |
18 | 18 | ||
@@ -23,7 +23,6 @@ use crate::{ | |||
23 | db::HirDatabase, | 23 | db::HirDatabase, |
24 | ty::display::HirDisplay, | 24 | ty::display::HirDisplay, |
25 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, | 25 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, |
26 | ImplBlock, | ||
27 | }; | 26 | }; |
28 | 27 | ||
29 | /// This represents a trait whose name we could not resolve. | 28 | /// This represents a trait whose name we could not resolve. |
@@ -435,14 +434,14 @@ where | |||
435 | fn struct_datum(&self, struct_id: chalk_ir::StructId) -> Arc<StructDatum<ChalkIr>> { | 434 | fn struct_datum(&self, struct_id: chalk_ir::StructId) -> Arc<StructDatum<ChalkIr>> { |
436 | self.db.struct_datum(self.krate, struct_id) | 435 | self.db.struct_datum(self.krate, struct_id) |
437 | } | 436 | } |
438 | fn impl_datum(&self, impl_id: ImplId) -> Arc<ImplDatum<ChalkIr>> { | 437 | fn impl_datum(&self, impl_id: chalk_ir::ImplId) -> Arc<ImplDatum<ChalkIr>> { |
439 | self.db.impl_datum(self.krate, impl_id) | 438 | self.db.impl_datum(self.krate, impl_id) |
440 | } | 439 | } |
441 | fn impls_for_trait( | 440 | fn impls_for_trait( |
442 | &self, | 441 | &self, |
443 | trait_id: chalk_ir::TraitId, | 442 | trait_id: chalk_ir::TraitId, |
444 | parameters: &[Parameter<ChalkIr>], | 443 | parameters: &[Parameter<ChalkIr>], |
445 | ) -> Vec<ImplId> { | 444 | ) -> Vec<chalk_ir::ImplId> { |
446 | debug!("impls_for_trait {:?}", trait_id); | 445 | debug!("impls_for_trait {:?}", trait_id); |
447 | if trait_id == UNKNOWN_TRAIT { | 446 | if trait_id == UNKNOWN_TRAIT { |
448 | return Vec::new(); | 447 | return Vec::new(); |
@@ -614,7 +613,7 @@ pub(crate) fn struct_datum_query( | |||
614 | pub(crate) fn impl_datum_query( | 613 | pub(crate) fn impl_datum_query( |
615 | db: &impl HirDatabase, | 614 | db: &impl HirDatabase, |
616 | krate: CrateId, | 615 | krate: CrateId, |
617 | impl_id: ImplId, | 616 | impl_id: chalk_ir::ImplId, |
618 | ) -> Arc<ImplDatum<ChalkIr>> { | 617 | ) -> Arc<ImplDatum<ChalkIr>> { |
619 | let _p = ra_prof::profile("impl_datum"); | 618 | let _p = ra_prof::profile("impl_datum"); |
620 | debug!("impl_datum {:?}", impl_id); | 619 | debug!("impl_datum {:?}", impl_id); |
@@ -629,23 +628,31 @@ pub(crate) fn impl_datum_query( | |||
629 | fn impl_block_datum( | 628 | fn impl_block_datum( |
630 | db: &impl HirDatabase, | 629 | db: &impl HirDatabase, |
631 | krate: CrateId, | 630 | krate: CrateId, |
631 | chalk_id: chalk_ir::ImplId, | ||
632 | impl_id: ImplId, | 632 | impl_id: ImplId, |
633 | impl_block: ImplBlock, | ||
634 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 633 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { |
635 | let generic_params = db.generic_params(impl_block.id.into()); | 634 | let impl_data = db.impl_data(impl_id); |
635 | let resolver = impl_id.resolver(db); | ||
636 | let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); | ||
637 | |||
638 | // `CoerseUnsized` has one generic parameter for the target type. | ||
639 | let trait_ref = | ||
640 | TraitRef::from_hir(db, &resolver, impl_data.target_trait.as_ref()?, Some(target_ty))?; | ||
641 | |||
642 | let generic_params = db.generic_params(impl_id.into()); | ||
636 | let bound_vars = Substs::bound_vars(&generic_params); | 643 | let bound_vars = Substs::bound_vars(&generic_params); |
637 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); | 644 | let trait_ref = trait_ref.subst(&bound_vars); |
638 | let trait_ = trait_ref.trait_; | 645 | let trait_ = trait_ref.trait_; |
639 | let impl_type = if impl_block.krate(db).crate_id == krate { | 646 | let impl_type = if impl_id.module(db).krate == krate { |
640 | chalk_rust_ir::ImplType::Local | 647 | chalk_rust_ir::ImplType::Local |
641 | } else { | 648 | } else { |
642 | chalk_rust_ir::ImplType::External | 649 | chalk_rust_ir::ImplType::External |
643 | }; | 650 | }; |
644 | let where_clauses = convert_where_clauses(db, impl_block.id.into(), &bound_vars); | 651 | let where_clauses = convert_where_clauses(db, impl_id.into(), &bound_vars); |
645 | let negative = impl_block.is_negative(db); | 652 | let negative = impl_data.is_negative; |
646 | debug!( | 653 | debug!( |
647 | "impl {:?}: {}{} where {:?}", | 654 | "impl {:?}: {}{} where {:?}", |
648 | impl_id, | 655 | chalk_id, |
649 | if negative { "!" } else { "" }, | 656 | if negative { "!" } else { "" }, |
650 | trait_ref.display(db), | 657 | trait_ref.display(db), |
651 | where_clauses | 658 | where_clauses |
@@ -660,18 +667,19 @@ fn impl_block_datum( | |||
660 | 667 | ||
661 | let impl_datum_bound = chalk_rust_ir::ImplDatumBound { trait_ref, where_clauses }; | 668 | let impl_datum_bound = chalk_rust_ir::ImplDatumBound { trait_ref, where_clauses }; |
662 | let trait_data = db.trait_data(trait_); | 669 | let trait_data = db.trait_data(trait_); |
663 | let associated_ty_value_ids = impl_block | 670 | let associated_ty_value_ids = impl_data |
664 | .items(db) | 671 | .items |
665 | .into_iter() | 672 | .iter() |
666 | .filter_map(|item| match item { | 673 | .filter_map(|item| match item { |
667 | crate::AssocItem::TypeAlias(type_alias) => Some(type_alias), | 674 | AssocItemId::TypeAliasId(type_alias) => Some(*type_alias), |
668 | _ => None, | 675 | _ => None, |
669 | }) | 676 | }) |
670 | .filter(|type_alias| { | 677 | .filter(|&type_alias| { |
671 | // don't include associated types that don't exist in the trait | 678 | // don't include associated types that don't exist in the trait |
672 | trait_data.associated_type_by_name(&type_alias.name(db)).is_some() | 679 | let name = &db.type_alias_data(type_alias).name; |
680 | trait_data.associated_type_by_name(name).is_some() | ||
673 | }) | 681 | }) |
674 | .map(|type_alias| AssocTyValue::TypeAlias(type_alias.id).to_chalk(db)) | 682 | .map(|type_alias| AssocTyValue::TypeAlias(type_alias).to_chalk(db)) |
675 | .collect(); | 683 | .collect(); |
676 | debug!("impl_datum: {:?}", impl_datum_bound); | 684 | debug!("impl_datum: {:?}", impl_datum_bound); |
677 | let impl_datum = ImplDatum { | 685 | let impl_datum = ImplDatum { |