diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-24 20:08:10 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-24 20:08:10 +0000 |
commit | 61d961263387f7293f3d0c4d7b8c8c9a07959ced (patch) | |
tree | b22232818d8d8ad8fff5b11b1656e2602115cd55 /crates/ra_hir/src/type_alias.rs | |
parent | 5a684099e9aa3482b408002030fafe1dcd0fa9a9 (diff) | |
parent | c3c09795614f31f988edc9cb051ce024d1996d89 (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/type_alias.rs')
-rw-r--r-- | crates/ra_hir/src/type_alias.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs new file mode 100644 index 000000000..ab9481708 --- /dev/null +++ b/crates/ra_hir/src/type_alias.rs | |||
@@ -0,0 +1,10 @@ | |||
1 | //! HIR for type aliases (i.e. the `type` keyword). | ||
2 | |||
3 | use std::sync::Arc; | ||
4 | |||
5 | use crate::{code_model_api::Type, db::PersistentHirDatabase, type_ref::TypeRef}; | ||
6 | |||
7 | pub(crate) fn type_alias_ref_query(db: &impl PersistentHirDatabase, typ: Type) -> Arc<TypeRef> { | ||
8 | let (_, node) = typ.source(db); | ||
9 | Arc::new(TypeRef::from_ast_opt(node.type_ref())) | ||
10 | } | ||