diff options
Diffstat (limited to 'crates/ra_hir_ty/src/infer/path.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer/path.rs | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 02fc99288..39aa346eb 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -10,8 +10,8 @@ use hir_def::{ | |||
10 | use hir_expand::name::Name; | 10 | use hir_expand::name::Name; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | db::HirDatabase, lower::ImplTraitLoweringMode, method_resolution, Substs, Ty, TypeWalk, | 13 | db::HirDatabase, method_resolution, Substs, Ty, |
14 | ValueTyDefId, | 14 | ValueTyDefId |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 17 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
@@ -42,11 +42,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
42 | } | 42 | } |
43 | let ty = self.make_ty(type_ref); | 43 | let ty = self.make_ty(type_ref); |
44 | let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); | 44 | let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); |
45 | let ctx = crate::lower::TyLoweringContext { | 45 | let ctx = crate::lower::TyLoweringContext::new(self.db, &resolver); |
46 | db: self.db, | ||
47 | resolver: &resolver, | ||
48 | impl_trait_mode: ImplTraitLoweringMode::Disallowed, | ||
49 | }; | ||
50 | let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty); | 46 | let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty); |
51 | self.resolve_ty_assoc_item( | 47 | self.resolve_ty_assoc_item( |
52 | ty, | 48 | ty, |
@@ -77,17 +73,16 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
77 | ValueNs::EnumVariantId(it) => it.into(), | 73 | ValueNs::EnumVariantId(it) => it.into(), |
78 | }; | 74 | }; |
79 | 75 | ||
80 | let mut ty = self.db.value_ty(typable); | 76 | let ty = self.db.value_ty(typable); |
81 | if let Some(self_subst) = self_subst { | 77 | // self_subst is just for the parent |
82 | ty = ty.subst(&self_subst); | 78 | let parent_substs = self_subst.unwrap_or_else(Substs::empty); |
83 | } | 79 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
84 | let ctx = crate::lower::TyLoweringContext { | ||
85 | db: self.db, | ||
86 | resolver: &self.resolver, | ||
87 | impl_trait_mode: ImplTraitLoweringMode::Disallowed, | ||
88 | }; | ||
89 | let substs = Ty::substs_from_path(&ctx, path, typable); | 80 | let substs = Ty::substs_from_path(&ctx, path, typable); |
90 | let ty = ty.subst(&substs); | 81 | let full_substs = Substs::builder(substs.len()) |
82 | .use_parent_substs(&parent_substs) | ||
83 | .fill(substs.0[parent_substs.len()..].iter().cloned()) | ||
84 | .build(); | ||
85 | let ty = ty.subst(&full_substs); | ||
91 | Some(ty) | 86 | Some(ty) |
92 | } | 87 | } |
93 | 88 | ||
@@ -111,11 +106,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
111 | (TypeNs::TraitId(trait_), true) => { | 106 | (TypeNs::TraitId(trait_), true) => { |
112 | let segment = | 107 | let segment = |
113 | remaining_segments.last().expect("there should be at least one segment here"); | 108 | remaining_segments.last().expect("there should be at least one segment here"); |
114 | let ctx = crate::lower::TyLoweringContext { | 109 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
115 | db: self.db, | ||
116 | resolver: &self.resolver, | ||
117 | impl_trait_mode: ImplTraitLoweringMode::Disallowed, | ||
118 | }; | ||
119 | let trait_ref = | 110 | let trait_ref = |
120 | TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); | 111 | TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); |
121 | self.resolve_trait_assoc_item(trait_ref, segment, id) | 112 | self.resolve_trait_assoc_item(trait_ref, segment, id) |
@@ -127,11 +118,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
127 | // as Iterator>::Item::default`) | 118 | // as Iterator>::Item::default`) |
128 | let remaining_segments_for_ty = | 119 | let remaining_segments_for_ty = |
129 | remaining_segments.take(remaining_segments.len() - 1); | 120 | remaining_segments.take(remaining_segments.len() - 1); |
130 | let ctx = crate::lower::TyLoweringContext { | 121 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
131 | db: self.db, | ||
132 | resolver: &self.resolver, | ||
133 | impl_trait_mode: ImplTraitLoweringMode::Disallowed, | ||
134 | }; | ||
135 | let ty = Ty::from_partly_resolved_hir_path( | 122 | let ty = Ty::from_partly_resolved_hir_path( |
136 | &ctx, | 123 | &ctx, |
137 | def, | 124 | def, |
@@ -235,12 +222,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
235 | .fill(iter::repeat_with(|| self.table.new_type_var())) | 222 | .fill(iter::repeat_with(|| self.table.new_type_var())) |
236 | .build(); | 223 | .build(); |
237 | let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); | 224 | let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); |
238 | let substs = Substs::build_for_def(self.db, item) | ||
239 | .use_parent_substs(&impl_substs) | ||
240 | .fill_with_params() | ||
241 | .build(); | ||
242 | self.unify(&impl_self_ty, &ty); | 225 | self.unify(&impl_self_ty, &ty); |
243 | Some(substs) | 226 | Some(impl_substs) |
244 | } | 227 | } |
245 | AssocContainerId::TraitId(trait_) => { | 228 | AssocContainerId::TraitId(trait_) => { |
246 | // we're picking this method | 229 | // we're picking this method |
@@ -248,15 +231,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
248 | .push(ty.clone()) | 231 | .push(ty.clone()) |
249 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) | 232 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) |
250 | .build(); | 233 | .build(); |
251 | let substs = Substs::build_for_def(self.db, item) | ||
252 | .use_parent_substs(&trait_substs) | ||
253 | .fill_with_params() | ||
254 | .build(); | ||
255 | self.obligations.push(super::Obligation::Trait(TraitRef { | 234 | self.obligations.push(super::Obligation::Trait(TraitRef { |
256 | trait_, | 235 | trait_, |
257 | substs: trait_substs, | 236 | substs: trait_substs.clone(), |
258 | })); | 237 | })); |
259 | Some(substs) | 238 | Some(trait_substs) |
260 | } | 239 | } |
261 | AssocContainerId::ContainerId(_) => None, | 240 | AssocContainerId::ContainerId(_) => None, |
262 | }; | 241 | }; |