aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/simple.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-29 15:13:41 +0100
committerGitHub <[email protected]>2020-06-29 15:13:41 +0100
commit82ce5792ab70ab8d20a1afde72c5400c27b9c190 (patch)
tree79cc454a617f30080a611b8ac66de849b0af53b7 /crates/ra_hir_ty/src/tests/simple.rs
parentca31b1d63ae91a69f1ce9c0b075403834ba19f38 (diff)
parent8e8d2ffecbc9e260ee5f0d37ba057b660e16076f (diff)
Merge #5124
5124: (Partially) fix handling of type params depending on type params r=matklad a=flodiebold 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. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests/simple.rs')
-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}