aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.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/ty/tests.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/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs35
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]
744fn infer_type_alias() {
745 check_inference(
746 "infer_type_alias",
747 r#"
748struct A<X, Y> { x: X, y: Y };
749type Foo = A<u32, i128>;
750type Bar<T> = A<T, u128>;
751type Baz<U, V> = A<V, U>;
752fn 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
766fn recursive_type_alias() {
767 check_inference(
768 "recursive_type_alias",
769 r#"
770struct A<X> {};
771type Foo = Foo;
772type Bar = A<Bar>;
773fn test(x: Foo) {}
774"#,
775 )
776}
777
778#[test]
744fn no_panic_on_field_of_enum() { 779fn 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",