aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/resolve.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-09-22 19:01:12 +0100
committerFlorian Diebold <[email protected]>2019-09-22 19:02:32 +0100
commit18bf278c258f44ed68f67f84993f20f7c27c63d0 (patch)
tree3c07347cee581c61107950b1ed9daed191027f5b /crates/ra_hir/src/resolve.rs
parent468e1d14c1a4b3d646207ae919082dc17753cd31 (diff)
Handle associated type shorthand (`T::Item`)
This is only allowed for generic parameters (including `Self` in traits), and special care needs to be taken to not run into cycles while resolving it, because we use the where clauses of the generic parameter to find candidates for the trait containing the associated type, but the where clauses may themselves contain instances of short-hand associated types. In some cases this is even fine, e.g. we might have `T: Trait<U::Item>, U: Iterator`. If there is a cycle, we'll currently panic, which isn't great, but better than overflowing the stack...
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r--crates/ra_hir/src/resolve.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 254d1a964..39f8e1d8a 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -344,6 +344,13 @@ impl Resolver {
344 }) 344 })
345 .flat_map(|params| params.where_predicates.iter()) 345 .flat_map(|params| params.where_predicates.iter())
346 } 346 }
347
348 pub(crate) fn generic_def(&self) -> Option<crate::generics::GenericDef> {
349 self.scopes.iter().find_map(|scope| match scope {
350 Scope::GenericParams(params) => Some(params.def),
351 _ => None,
352 })
353 }
347} 354}
348 355
349impl Resolver { 356impl Resolver {