diff options
author | Florian Diebold <[email protected]> | 2020-04-12 11:29:03 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-04-13 15:32:23 +0100 |
commit | d88d67819b3f052422ad3f024e44ad73dde1630b (patch) | |
tree | 990564fefe3e9b907ea7dea59563703e2165c08e /crates/ra_hir_ty/src/lower.rs | |
parent | c388130f5ffbcbe7d3131213a24d12d02f769b87 (diff) |
Handle `Self::Type` in trait definitions when referring to own associated type
It was implemented for other generic parameters for the trait, but not for `Self`.
Diffstat (limited to 'crates/ra_hir_ty/src/lower.rs')
-rw-r--r-- | crates/ra_hir_ty/src/lower.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 6c7bbc448..7b5990a47 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs | |||
@@ -360,13 +360,23 @@ impl Ty { | |||
360 | }, | 360 | }, |
361 | Some(TypeNs::GenericParam(param_id)) => { | 361 | Some(TypeNs::GenericParam(param_id)) => { |
362 | let predicates = ctx.db.generic_predicates_for_param(param_id); | 362 | let predicates = ctx.db.generic_predicates_for_param(param_id); |
363 | predicates | 363 | let mut traits_: Vec<_> = predicates |
364 | .iter() | 364 | .iter() |
365 | .filter_map(|pred| match &pred.value { | 365 | .filter_map(|pred| match &pred.value { |
366 | GenericPredicate::Implemented(tr) => Some(tr.trait_), | 366 | GenericPredicate::Implemented(tr) => Some(tr.trait_), |
367 | _ => None, | 367 | _ => None, |
368 | }) | 368 | }) |
369 | .collect() | 369 | .collect(); |
370 | // Handle `Self::Type` referring to own associated type in trait definitions | ||
371 | if let GenericDefId::TraitId(trait_id) = param_id.parent { | ||
372 | let generics = generics(ctx.db.upcast(), trait_id.into()); | ||
373 | if generics.params.types[param_id.local_id].provenance | ||
374 | == TypeParamProvenance::TraitSelf | ||
375 | { | ||
376 | traits_.push(trait_id); | ||
377 | } | ||
378 | } | ||
379 | traits_ | ||
370 | } | 380 | } |
371 | _ => return Ty::Unknown, | 381 | _ => return Ty::Unknown, |
372 | }; | 382 | }; |