diff options
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r-- | crates/ra_hir_ty/src/infer/coerce.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/path.rs | 10 |
2 files changed, 10 insertions, 22 deletions
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index d66a21932..719a0f395 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs | |||
@@ -4,16 +4,11 @@ | |||
4 | //! | 4 | //! |
5 | //! See: https://doc.rust-lang.org/nomicon/coercions.html | 5 | //! See: https://doc.rust-lang.org/nomicon/coercions.html |
6 | 6 | ||
7 | use hir_def::{ | 7 | use hir_def::{lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AdtId}; |
8 | lang_item::LangItemTarget, | ||
9 | resolver::{HasResolver, Resolver}, | ||
10 | type_ref::Mutability, | ||
11 | AdtId, | ||
12 | }; | ||
13 | use rustc_hash::FxHashMap; | 8 | use rustc_hash::FxHashMap; |
14 | use test_utils::tested_by; | 9 | use test_utils::tested_by; |
15 | 10 | ||
16 | use crate::{autoderef, db::HirDatabase, Substs, TraitRef, Ty, TypeCtor, TypeWalk}; | 11 | use crate::{autoderef, db::HirDatabase, ImplTy, Substs, Ty, TypeCtor, TypeWalk}; |
17 | 12 | ||
18 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; | 13 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; |
19 | 14 | ||
@@ -59,17 +54,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
59 | impls | 54 | impls |
60 | .iter() | 55 | .iter() |
61 | .filter_map(|&impl_id| { | 56 | .filter_map(|&impl_id| { |
62 | let impl_data = db.impl_data(impl_id); | 57 | let trait_ref = match db.impl_ty(impl_id) { |
63 | let resolver = impl_id.resolver(db); | 58 | ImplTy::TraitRef(it) => it, |
64 | let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); | 59 | ImplTy::Inherent(_) => return None, |
60 | }; | ||
65 | 61 | ||
66 | // `CoerseUnsized` has one generic parameter for the target type. | 62 | // `CoerseUnsized` has one generic parameter for the target type. |
67 | let trait_ref = TraitRef::from_hir( | ||
68 | db, | ||
69 | &resolver, | ||
70 | impl_data.target_trait.as_ref()?, | ||
71 | Some(target_ty), | ||
72 | )?; | ||
73 | let cur_from_ty = trait_ref.substs.0.get(0)?; | 63 | let cur_from_ty = trait_ref.substs.0.get(0)?; |
74 | let cur_to_ty = trait_ref.substs.0.get(1)?; | 64 | let cur_to_ty = trait_ref.substs.0.get(1)?; |
75 | 65 | ||
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index e6676e1aa..14be66836 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use hir_def::{ | 3 | use hir_def::{ |
4 | path::{Path, PathKind, PathSegment}, | 4 | path::{Path, PathKind, PathSegment}, |
5 | resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs}, | 5 | resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs}, |
6 | AssocItemId, ContainerId, Lookup, | 6 | AssocItemId, ContainerId, Lookup, |
7 | }; | 7 | }; |
8 | use hir_expand::name::Name; | 8 | use hir_expand::name::Name; |
@@ -244,17 +244,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
244 | ContainerId::ImplId(it) => it, | 244 | ContainerId::ImplId(it) => it, |
245 | _ => return None, | 245 | _ => return None, |
246 | }; | 246 | }; |
247 | let resolver = impl_id.resolver(self.db); | 247 | let self_ty = self.db.impl_ty(impl_id).self_type().clone(); |
248 | let impl_data = self.db.impl_data(impl_id); | 248 | let self_ty_substs = self_ty.substs()?; |
249 | let impl_block = Ty::from_hir(self.db, &resolver, &impl_data.target_type); | ||
250 | let impl_block_substs = impl_block.substs()?; | ||
251 | let actual_substs = actual_def_ty.substs()?; | 249 | let actual_substs = actual_def_ty.substs()?; |
252 | 250 | ||
253 | let mut new_substs = vec![Ty::Unknown; gen.count_parent_params()]; | 251 | let mut new_substs = vec![Ty::Unknown; gen.count_parent_params()]; |
254 | 252 | ||
255 | // The following code *link up* the function actual parma type | 253 | // The following code *link up* the function actual parma type |
256 | // and impl_block type param index | 254 | // and impl_block type param index |
257 | impl_block_substs.iter().zip(actual_substs.iter()).for_each(|(param, pty)| { | 255 | self_ty_substs.iter().zip(actual_substs.iter()).for_each(|(param, pty)| { |
258 | if let Ty::Param { idx, .. } = param { | 256 | if let Ty::Param { idx, .. } = param { |
259 | if let Some(s) = new_substs.get_mut(*idx as usize) { | 257 | if let Some(s) = new_substs.get_mut(*idx as usize) { |
260 | *s = pty.clone(); | 258 | *s = pty.clone(); |