aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs21
-rw-r--r--crates/ra_hir/src/ty/traits.rs6
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs2
3 files changed, 21 insertions, 8 deletions
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 @@
4//! 4//!
5//! See: https://doc.rust-lang.org/nomicon/coercions.html 5//! See: https://doc.rust-lang.org/nomicon/coercions.html
6 6
7use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AdtId}; 7use hir_def::{
8 lang_item::LangItemTarget,
9 resolver::{HasResolver, Resolver},
10 AdtId,
11};
8use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
9use test_utils::tested_by; 13use test_utils::tested_by;
10 14
11use crate::{ 15use crate::{
12 db::HirDatabase, 16 db::HirDatabase,
13 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, 17 ty::{autoderef, Substs, TraitRef, Ty, TypeCtor, TypeWalk},
14 Mutability, 18 Mutability,
15}; 19};
16 20
@@ -57,9 +61,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
57 61
58 impls 62 impls
59 .iter() 63 .iter()
60 .filter_map(|impl_block| { 64 .filter_map(|&impl_id| {
65 let impl_data = db.impl_data(impl_id);
66 let resolver = impl_id.resolver(db);
67 let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
68
61 // `CoerseUnsized` has one generic parameter for the target type. 69 // `CoerseUnsized` has one generic parameter for the target type.
62 let trait_ref = impl_block.target_trait_ref(db)?; 70 let trait_ref = TraitRef::from_hir(
71 db,
72 &resolver,
73 impl_data.target_trait.as_ref()?,
74 Some(target_ty),
75 )?;
63 let cur_from_ty = trait_ref.substs.0.get(0)?; 76 let cur_from_ty = trait_ref.substs.0.get(0)?;
64 let cur_to_ty = trait_ref.substs.0.get(1)?; 77 let cur_to_ty = trait_ref.substs.0.get(1)?;
65 78
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 @@
2use std::sync::{Arc, Mutex}; 2use std::sync::{Arc, Mutex};
3 3
4use chalk_ir::{cast::Cast, family::ChalkIr}; 4use chalk_ir::{cast::Cast, family::ChalkIr};
5use hir_def::{expr::ExprId, DefWithBodyId, TraitId, TypeAliasId}; 5use hir_def::{expr::ExprId, DefWithBodyId, ImplId, TraitId, TypeAliasId};
6use log::debug; 6use log::debug;
7use ra_db::{impl_intern_key, salsa, CrateId}; 7use ra_db::{impl_intern_key, salsa, CrateId};
8use ra_prof::profile; 8use ra_prof::profile;
@@ -79,7 +79,7 @@ pub(crate) fn impls_for_trait_query(
79 db: &impl HirDatabase, 79 db: &impl HirDatabase,
80 krate: CrateId, 80 krate: CrateId,
81 trait_: TraitId, 81 trait_: TraitId,
82) -> Arc<[ImplBlock]> { 82) -> Arc<[ImplId]> {
83 let mut impls = FxHashSet::default(); 83 let mut impls = FxHashSet::default();
84 // We call the query recursively here. On the one hand, this means we can 84 // We call the query recursively here. On the one hand, this means we can
85 // reuse results from queries for different crates; on the other hand, this 85 // reuse results from queries for different crates; on the other hand, this
@@ -90,7 +90,7 @@ pub(crate) fn impls_for_trait_query(
90 impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); 90 impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter());
91 } 91 }
92 let crate_impl_blocks = db.impls_in_crate(krate); 92 let crate_impl_blocks = db.impls_in_crate(krate);
93 impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_).map(ImplBlock::from)); 93 impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_));
94 impls.into_iter().collect() 94 impls.into_iter().collect()
95} 95}
96 96
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
453 .impls_for_trait(self.krate, trait_.into()) 453 .impls_for_trait(self.krate, trait_.into())
454 .iter() 454 .iter()
455 .copied() 455 .copied()
456 .map(Impl::ImplBlock) 456 .map(|it| Impl::ImplBlock(it.into()))
457 .map(|impl_| impl_.to_chalk(self.db)) 457 .map(|impl_| impl_.to_chalk(self.db))
458 .collect(); 458 .collect();
459 459