From 3a0929fca7a52605526c6f89be4e3e86c5d0359d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 12:02:54 +0300 Subject: Decouple --- crates/ra_hir/src/ty/infer/coerce.rs | 21 +++++++++++++++++---- crates/ra_hir/src/ty/traits.rs | 6 +++--- crates/ra_hir/src/ty/traits/chalk.rs | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs index 5ed4470af..cf45ede7c 100644 --- a/crates/ra_hir/src/ty/infer/coerce.rs +++ b/crates/ra_hir/src/ty/infer/coerce.rs @@ -4,13 +4,17 @@ //! //! See: https://doc.rust-lang.org/nomicon/coercions.html -use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AdtId}; +use hir_def::{ + lang_item::LangItemTarget, + resolver::{HasResolver, Resolver}, + AdtId, +}; use rustc_hash::FxHashMap; use test_utils::tested_by; use crate::{ db::HirDatabase, - ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, + ty::{autoderef, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, Mutability, }; @@ -57,9 +61,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { impls .iter() - .filter_map(|impl_block| { + .filter_map(|&impl_id| { + let impl_data = db.impl_data(impl_id); + let resolver = impl_id.resolver(db); + let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); + // `CoerseUnsized` has one generic parameter for the target type. - let trait_ref = impl_block.target_trait_ref(db)?; + let trait_ref = TraitRef::from_hir( + db, + &resolver, + impl_data.target_trait.as_ref()?, + Some(target_ty), + )?; let cur_from_ty = trait_ref.substs.0.get(0)?; let cur_to_ty = trait_ref.substs.0.get(1)?; diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 99afeb35f..93cb32869 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex}; use chalk_ir::{cast::Cast, family::ChalkIr}; -use hir_def::{expr::ExprId, DefWithBodyId, TraitId, TypeAliasId}; +use hir_def::{expr::ExprId, DefWithBodyId, ImplId, TraitId, TypeAliasId}; use log::debug; use ra_db::{impl_intern_key, salsa, CrateId}; use ra_prof::profile; @@ -79,7 +79,7 @@ pub(crate) fn impls_for_trait_query( db: &impl HirDatabase, krate: CrateId, trait_: TraitId, -) -> Arc<[ImplBlock]> { +) -> Arc<[ImplId]> { let mut impls = FxHashSet::default(); // We call the query recursively here. On the one hand, this means we can // reuse results from queries for different crates; on the other hand, this @@ -90,7 +90,7 @@ pub(crate) fn impls_for_trait_query( impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); } let crate_impl_blocks = db.impls_in_crate(krate); - impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_).map(ImplBlock::from)); + impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_)); impls.into_iter().collect() } diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 76ff6f67f..7b2e530a2 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -453,7 +453,7 @@ where .impls_for_trait(self.krate, trait_.into()) .iter() .copied() - .map(Impl::ImplBlock) + .map(|it| Impl::ImplBlock(it.into())) .map(|impl_| impl_.to_chalk(self.db)) .collect(); -- cgit v1.2.3