aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer/path.rs')
-rw-r--r--crates/hir_ty/src/infer/path.rs39
1 files changed, 16 insertions, 23 deletions
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs
index cefa38509..495282eba 100644
--- a/crates/hir_ty/src/infer/path.rs
+++ b/crates/hir_ty/src/infer/path.rs
@@ -11,7 +11,8 @@ use hir_def::{
11use hir_expand::name::Name; 11use hir_expand::name::Name;
12 12
13use crate::{ 13use crate::{
14 method_resolution, to_chalk_trait_id, Interner, Substitution, Ty, TyKind, ValueTyDefId, 14 method_resolution, Interner, Substitution, TraitRefExt, Ty, TyBuilder, TyExt, TyKind,
15 ValueTyDefId,
15}; 16};
16 17
17use super::{ExprOrPatId, InferenceContext, TraitRef}; 18use super::{ExprOrPatId, InferenceContext, TraitRef};
@@ -82,10 +83,10 @@ impl<'a> InferenceContext<'a> {
82 } 83 }
83 ValueNs::ImplSelf(impl_id) => { 84 ValueNs::ImplSelf(impl_id) => {
84 let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); 85 let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
85 let substs = Substitution::type_params_for_generics(self.db, &generics); 86 let substs = generics.type_params_subst(self.db);
86 let ty = self.db.impl_self_ty(impl_id).subst(&substs); 87 let ty = self.db.impl_self_ty(impl_id).substitute(&Interner, &substs);
87 if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { 88 if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
88 let ty = self.db.value_ty(struct_id.into()).subst(&substs); 89 let ty = self.db.value_ty(struct_id.into()).substitute(&Interner, &substs);
89 return Some(ty); 90 return Some(ty);
90 } else { 91 } else {
91 // FIXME: diagnostic, invalid Self reference 92 // FIXME: diagnostic, invalid Self reference
@@ -95,16 +96,13 @@ impl<'a> InferenceContext<'a> {
95 ValueNs::GenericParam(it) => return Some(self.db.const_param_ty(it)), 96 ValueNs::GenericParam(it) => return Some(self.db.const_param_ty(it)),
96 }; 97 };
97 98
98 let ty = self.db.value_ty(typable); 99 let parent_substs = self_subst.unwrap_or_else(|| Substitution::empty(&Interner));
99 // self_subst is just for the parent
100 let parent_substs = self_subst.unwrap_or_else(Substitution::empty);
101 let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); 100 let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver);
102 let substs = ctx.substs_from_path(path, typable, true); 101 let substs = ctx.substs_from_path(path, typable, true);
103 let full_substs = Substitution::builder(substs.len()) 102 let ty = TyBuilder::value_ty(self.db, typable)
104 .use_parent_substs(&parent_substs) 103 .use_parent_substs(&parent_substs)
105 .fill(substs.0[parent_substs.len()..].iter().cloned()) 104 .fill(substs.as_slice(&Interner)[parent_substs.len(&Interner)..].iter().cloned())
106 .build(); 105 .build();
107 let ty = ty.subst(&full_substs);
108 Some(ty) 106 Some(ty)
109 } 107 }
110 108
@@ -147,7 +145,7 @@ impl<'a> InferenceContext<'a> {
147 remaining_segments_for_ty, 145 remaining_segments_for_ty,
148 true, 146 true,
149 ); 147 );
150 if let TyKind::Unknown = ty.interned(&Interner) { 148 if let TyKind::Error = ty.kind(&Interner) {
151 return None; 149 return None;
152 } 150 }
153 151
@@ -212,7 +210,7 @@ impl<'a> InferenceContext<'a> {
212 name: &Name, 210 name: &Name,
213 id: ExprOrPatId, 211 id: ExprOrPatId,
214 ) -> Option<(ValueNs, Option<Substitution>)> { 212 ) -> Option<(ValueNs, Option<Substitution>)> {
215 if let TyKind::Unknown = ty.interned(&Interner) { 213 if let TyKind::Error = ty.kind(&Interner) {
216 return None; 214 return None;
217 } 215 }
218 216
@@ -245,27 +243,22 @@ impl<'a> InferenceContext<'a> {
245 }; 243 };
246 let substs = match container { 244 let substs = match container {
247 AssocContainerId::ImplId(impl_id) => { 245 AssocContainerId::ImplId(impl_id) => {
248 let impl_substs = Substitution::build_for_def(self.db, impl_id) 246 let impl_substs = TyBuilder::subst_for_def(self.db, impl_id)
249 .fill(iter::repeat_with(|| self.table.new_type_var())) 247 .fill(iter::repeat_with(|| self.table.new_type_var()))
250 .build(); 248 .build();
251 let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); 249 let impl_self_ty =
250 self.db.impl_self_ty(impl_id).substitute(&Interner, &impl_substs);
252 self.unify(&impl_self_ty, &ty); 251 self.unify(&impl_self_ty, &ty);
253 Some(impl_substs) 252 Some(impl_substs)
254 } 253 }
255 AssocContainerId::TraitId(trait_) => { 254 AssocContainerId::TraitId(trait_) => {
256 // we're picking this method 255 // we're picking this method
257 let trait_substs = Substitution::build_for_def(self.db, trait_) 256 let trait_ref = TyBuilder::trait_ref(self.db, trait_)
258 .push(ty.clone()) 257 .push(ty.clone())
259 .fill(std::iter::repeat_with(|| self.table.new_type_var())) 258 .fill(std::iter::repeat_with(|| self.table.new_type_var()))
260 .build(); 259 .build();
261 self.obligations.push( 260 self.push_obligation(trait_ref.clone().cast(&Interner));
262 TraitRef { 261 Some(trait_ref.substitution)
263 trait_id: to_chalk_trait_id(trait_),
264 substitution: trait_substs.clone(),
265 }
266 .cast(&Interner),
267 );
268 Some(trait_substs)
269 } 262 }
270 AssocContainerId::ModuleId(_) => None, 263 AssocContainerId::ModuleId(_) => None,
271 }; 264 };