aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-06-26 15:36:59 +0100
committerFlorian Diebold <[email protected]>2020-06-29 15:10:20 +0100
commit8e8d2ffecbc9e260ee5f0d37ba057b660e16076f (patch)
tree0a7a4a79b56a0cfce21421537d5dbbf55ec7c28c /crates/ra_hir_ty/src/tests
parent117cf0b85bc8022a939fe43054f64aaa35117dd9 (diff)
(Partially) fix handling of type params depending on type params
If the first type parameter gets inferred, that's still not handled correctly; it'll require some more refactoring: E.g. if we have `Thing<T, F=fn() -> T>` and then instantiate `Thing<_>`, that gets turned into `Thing<_, fn() -> _>` before the `_` is instantiated into a type variable -- so afterwards, we have two type variables without any connection to each other.
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index cd919466f..5e3f2bd3c 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -2152,3 +2152,48 @@ fn test() {
2152 "### 2152 "###
2153 ); 2153 );
2154} 2154}
2155
2156#[test]
2157fn generic_default_depending_on_other_type_arg() {
2158 assert_snapshot!(
2159 infer(r#"
2160struct Thing<T = u128, F = fn() -> T> { t: T }
2161
2162fn test(t1: Thing<u32>, t2: Thing) {
2163 t1;
2164 t2;
2165 Thing::<_> { t: 1u32 };
2166}
2167"#),
2168 // FIXME: the {unknown} is a bug
2169 @r###"
2170 56..58 't1': Thing<u32, fn() -> u32>
2171 72..74 't2': Thing<u128, fn() -> u128>
2172 83..130 '{ ...2 }; }': ()
2173 89..91 't1': Thing<u32, fn() -> u32>
2174 97..99 't2': Thing<u128, fn() -> u128>
2175 105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
2176 121..125 '1u32': u32
2177 "###
2178 );
2179}
2180
2181#[test]
2182fn generic_default_depending_on_other_type_arg_forward() {
2183 assert_snapshot!(
2184 infer(r#"
2185struct Thing<F = fn() -> T, T = u128> { t: T }
2186
2187fn test(t1: Thing) {
2188 t1;
2189}
2190"#),
2191 // the {unknown} here is intentional, as defaults are not allowed to
2192 // refer to type parameters coming later
2193 @r###"
2194 56..58 't1': Thing<fn() -> {unknown}, u128>
2195 67..78 '{ t1; }': ()
2196 73..75 't1': Thing<fn() -> {unknown}, u128>
2197 "###
2198 );
2199}