diff options
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 5dce2f342..2d447f1ea 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -31,7 +31,6 @@ use crate::{ | |||
31 | utils::{all_super_traits, associated_type_by_name_including_super_traits, variant_data}, | 31 | utils::{all_super_traits, associated_type_by_name_including_super_traits, variant_data}, |
32 | }, | 32 | }, |
33 | util::make_mut_slice, | 33 | util::make_mut_slice, |
34 | ImplBlock, Trait, | ||
35 | }; | 34 | }; |
36 | 35 | ||
37 | impl Ty { | 36 | impl Ty { |
@@ -148,13 +147,8 @@ impl Ty { | |||
148 | ) -> Ty { | 147 | ) -> Ty { |
149 | let ty = match resolution { | 148 | let ty = match resolution { |
150 | TypeNs::TraitId(trait_) => { | 149 | TypeNs::TraitId(trait_) => { |
151 | let trait_ref = TraitRef::from_resolved_path( | 150 | let trait_ref = |
152 | db, | 151 | TraitRef::from_resolved_path(db, resolver, trait_, resolved_segment, None); |
153 | resolver, | ||
154 | trait_.into(), | ||
155 | resolved_segment, | ||
156 | None, | ||
157 | ); | ||
158 | return if remaining_segments.len() == 1 { | 152 | return if remaining_segments.len() == 1 { |
159 | let segment = &remaining_segments[0]; | 153 | let segment = &remaining_segments[0]; |
160 | let associated_ty = associated_type_by_name_including_super_traits( | 154 | let associated_ty = associated_type_by_name_including_super_traits( |
@@ -187,7 +181,11 @@ impl Ty { | |||
187 | let name = resolved_segment.name.clone(); | 181 | let name = resolved_segment.name.clone(); |
188 | Ty::Param { idx, name } | 182 | Ty::Param { idx, name } |
189 | } | 183 | } |
190 | TypeNs::SelfType(impl_block) => ImplBlock::from(impl_block).target_ty(db), | 184 | TypeNs::SelfType(impl_id) => { |
185 | let impl_data = db.impl_data(impl_id); | ||
186 | let resolver = impl_id.resolver(db); | ||
187 | Ty::from_hir(db, &resolver, &impl_data.target_type) | ||
188 | } | ||
191 | TypeNs::AdtSelfType(adt) => db.ty(adt.into()), | 189 | TypeNs::AdtSelfType(adt) => db.ty(adt.into()), |
192 | 190 | ||
193 | TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()), | 191 | TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()), |
@@ -250,14 +248,11 @@ impl Ty { | |||
250 | GenericPredicate::Implemented(tr) if tr.self_ty() == &self_ty => Some(tr.trait_), | 248 | GenericPredicate::Implemented(tr) if tr.self_ty() == &self_ty => Some(tr.trait_), |
251 | _ => None, | 249 | _ => None, |
252 | }); | 250 | }); |
253 | let traits = traits_from_env.flat_map(|t| all_super_traits(db, t)).map(Trait::from); | 251 | let traits = traits_from_env.flat_map(|t| all_super_traits(db, t)); |
254 | for t in traits { | 252 | for t in traits { |
255 | if let Some(associated_ty) = db.trait_data(t.id).associated_type_by_name(&segment.name) | 253 | if let Some(associated_ty) = db.trait_data(t).associated_type_by_name(&segment.name) { |
256 | { | 254 | let substs = |
257 | let substs = Substs::build_for_def(db, t.id) | 255 | Substs::build_for_def(db, t).push(self_ty.clone()).fill_with_unknown().build(); |
258 | .push(self_ty.clone()) | ||
259 | .fill_with_unknown() | ||
260 | .build(); | ||
261 | // FIXME handle type parameters on the segment | 256 | // FIXME handle type parameters on the segment |
262 | return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); | 257 | return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); |
263 | } | 258 | } |
@@ -391,7 +386,7 @@ impl TraitRef { | |||
391 | pub(super) fn from_resolved_path( | 386 | pub(super) fn from_resolved_path( |
392 | db: &impl HirDatabase, | 387 | db: &impl HirDatabase, |
393 | resolver: &Resolver, | 388 | resolver: &Resolver, |
394 | resolved: Trait, | 389 | resolved: TraitId, |
395 | segment: &PathSegment, | 390 | segment: &PathSegment, |
396 | explicit_self_ty: Option<Ty>, | 391 | explicit_self_ty: Option<Ty>, |
397 | ) -> Self { | 392 | ) -> Self { |
@@ -399,7 +394,7 @@ impl TraitRef { | |||
399 | if let Some(self_ty) = explicit_self_ty { | 394 | if let Some(self_ty) = explicit_self_ty { |
400 | make_mut_slice(&mut substs.0)[0] = self_ty; | 395 | make_mut_slice(&mut substs.0)[0] = self_ty; |
401 | } | 396 | } |
402 | TraitRef { trait_: resolved.id, substs } | 397 | TraitRef { trait_: resolved, substs } |
403 | } | 398 | } |
404 | 399 | ||
405 | pub(crate) fn from_hir( | 400 | pub(crate) fn from_hir( |
@@ -419,11 +414,11 @@ impl TraitRef { | |||
419 | db: &impl HirDatabase, | 414 | db: &impl HirDatabase, |
420 | resolver: &Resolver, | 415 | resolver: &Resolver, |
421 | segment: &PathSegment, | 416 | segment: &PathSegment, |
422 | resolved: Trait, | 417 | resolved: TraitId, |
423 | ) -> Substs { | 418 | ) -> Substs { |
424 | let has_self_param = | 419 | let has_self_param = |
425 | segment.args_and_bindings.as_ref().map(|a| a.has_self_type).unwrap_or(false); | 420 | segment.args_and_bindings.as_ref().map(|a| a.has_self_type).unwrap_or(false); |
426 | substs_from_path_segment(db, resolver, segment, Some(resolved.id.into()), !has_self_param) | 421 | substs_from_path_segment(db, resolver, segment, Some(resolved.into()), !has_self_param) |
427 | } | 422 | } |
428 | 423 | ||
429 | pub(crate) fn for_trait(db: &impl HirDatabase, trait_: TraitId) -> TraitRef { | 424 | pub(crate) fn for_trait(db: &impl HirDatabase, trait_: TraitId) -> TraitRef { |