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/ty/tests.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/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index d0da34677..642259225 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -741,6 +741,41 @@ fn test() { | |||
741 | } | 741 | } |
742 | 742 | ||
743 | #[test] | 743 | #[test] |
744 | fn infer_type_alias() { | ||
745 | check_inference( | ||
746 | "infer_type_alias", | ||
747 | r#" | ||
748 | struct A<X, Y> { x: X, y: Y }; | ||
749 | type Foo = A<u32, i128>; | ||
750 | type Bar<T> = A<T, u128>; | ||
751 | type Baz<U, V> = A<V, U>; | ||
752 | fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) { | ||
753 | x.x; | ||
754 | x.y; | ||
755 | y.x; | ||
756 | y.y; | ||
757 | z.x; | ||
758 | z.y; | ||
759 | } | ||
760 | "#, | ||
761 | ) | ||
762 | } | ||
763 | |||
764 | #[test] | ||
765 | #[should_panic] // we currently can't handle this | ||
766 | fn recursive_type_alias() { | ||
767 | check_inference( | ||
768 | "recursive_type_alias", | ||
769 | r#" | ||
770 | struct A<X> {}; | ||
771 | type Foo = Foo; | ||
772 | type Bar = A<Bar>; | ||
773 | fn test(x: Foo) {} | ||
774 | "#, | ||
775 | ) | ||
776 | } | ||
777 | |||
778 | #[test] | ||
744 | fn no_panic_on_field_of_enum() { | 779 | fn no_panic_on_field_of_enum() { |
745 | check_inference( | 780 | check_inference( |
746 | "no_panic_on_field_of_enum", | 781 | "no_panic_on_field_of_enum", |