From 8e8d2ffecbc9e260ee5f0d37ba057b660e16076f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 26 Jun 2020 16:36:59 +0200 Subject: (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>` 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. --- crates/ra_hir_ty/src/tests/simple.rs | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') 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() { "### ); } + +#[test] +fn generic_default_depending_on_other_type_arg() { + assert_snapshot!( + infer(r#" +struct Thing T> { t: T } + +fn test(t1: Thing, t2: Thing) { + t1; + t2; + Thing::<_> { t: 1u32 }; +} +"#), + // FIXME: the {unknown} is a bug + @r###" + 56..58 't1': Thing u32> + 72..74 't2': Thing u128> + 83..130 '{ ...2 }; }': () + 89..91 't1': Thing u32> + 97..99 't2': Thing u128> + 105..127 'Thing:...1u32 }': Thing {unknown}> + 121..125 '1u32': u32 + "### + ); +} + +#[test] +fn generic_default_depending_on_other_type_arg_forward() { + assert_snapshot!( + infer(r#" +struct Thing T, T = u128> { t: T } + +fn test(t1: Thing) { + t1; +} +"#), + // the {unknown} here is intentional, as defaults are not allowed to + // refer to type parameters coming later + @r###" + 56..58 't1': Thing {unknown}, u128> + 67..78 '{ t1; }': () + 73..75 't1': Thing {unknown}, u128> + "### + ); +} -- cgit v1.2.3