aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-24 20:08:10 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-24 20:08:10 +0000
commit61d961263387f7293f3d0c4d7b8c8c9a07959ced (patch)
treeb22232818d8d8ad8fff5b11b1656e2602115cd55 /crates/ra_hir/src/code_model_api.rs
parent5a684099e9aa3482b408002030fafe1dcd0fa9a9 (diff)
parentc3c09795614f31f988edc9cb051ce024d1996d89 (diff)
Merge #892
892: Type aliases r=matklad a=flodiebold This implements type aliases (i.e. `type` definitions). There's just one snag: handling recursion. E.g. `type Foo = Foo` makes type inference panic with a query cycle. I think the best way to handle this would be if Salsa provided the ability to catch cycle errors? It seems that there's some work underway to support this [here](https://github.com/salsa-rs/salsa/issues/6) and [here](https://github.com/salsa-rs/salsa/pull/147). Should we wait for this? I don't see a good way to handle this without help from Salsa. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 0779a08a9..29c08e34b 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -626,6 +626,23 @@ impl Type {
626 let module_impls = db.impls_in_module(self.module(db)); 626 let module_impls = db.impls_in_module(self.module(db));
627 ImplBlock::containing(module_impls, (*self).into()) 627 ImplBlock::containing(module_impls, (*self).into())
628 } 628 }
629
630 pub fn type_ref(self, db: &impl PersistentHirDatabase) -> Arc<TypeRef> {
631 db.type_alias_ref(self)
632 }
633
634 /// Builds a resolver for the type references in this type alias.
635 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
636 // take the outer scope...
637 let r = self
638 .impl_block(db)
639 .map(|ib| ib.resolver(db))
640 .unwrap_or_else(|| self.module(db).resolver(db));
641 // ...and add generic params, if present
642 let p = self.generic_params(db);
643 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
644 r
645 }
629} 646}
630 647
631impl Docs for Type { 648impl Docs for Type {