From afa6be243587e523d5a2fc218db78568041ff296 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 13 May 2021 20:31:06 +0200 Subject: Update tests with expected changes --- crates/hir_ty/src/tests/regression.rs | 71 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 37 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 431861712..59a16f390 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs @@ -86,8 +86,6 @@ fn bug_651() { #[test] fn recursive_vars() { - cov_mark::check!(type_var_cycles_resolve_completely); - cov_mark::check!(type_var_cycles_resolve_as_possible); check_infer( r#" fn test() { @@ -97,12 +95,12 @@ fn recursive_vars() { "#, expect![[r#" 10..47 '{ ...&y]; }': () - 20..21 'y': &{unknown} - 24..31 'unknown': &{unknown} - 37..44 '[y, &y]': [&&{unknown}; 2] - 38..39 'y': &{unknown} - 41..43 '&y': &&{unknown} - 42..43 'y': &{unknown} + 20..21 'y': {unknown} + 24..31 'unknown': {unknown} + 37..44 '[y, &y]': [{unknown}; 2] + 38..39 'y': {unknown} + 41..43 '&y': &{unknown} + 42..43 'y': {unknown} "#]], ); } @@ -119,19 +117,19 @@ fn recursive_vars_2() { "#, expect![[r#" 10..79 '{ ...x)]; }': () - 20..21 'x': &&{unknown} - 24..31 'unknown': &&{unknown} - 41..42 'y': &&{unknown} - 45..52 'unknown': &&{unknown} - 58..76 '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown}); 2] - 59..65 '(x, y)': (&&&{unknown}, &&&{unknown}) - 60..61 'x': &&{unknown} - 63..64 'y': &&{unknown} - 67..75 '(&y, &x)': (&&&{unknown}, &&&{unknown}) - 68..70 '&y': &&&{unknown} - 69..70 'y': &&{unknown} - 72..74 '&x': &&&{unknown} - 73..74 'x': &&{unknown} + 20..21 'x': {unknown} + 24..31 'unknown': {unknown} + 41..42 'y': {unknown} + 45..52 'unknown': {unknown} + 58..76 '[(x, y..., &x)]': [({unknown}, {unknown}); 2] + 59..65 '(x, y)': ({unknown}, {unknown}) + 60..61 'x': {unknown} + 63..64 'y': {unknown} + 67..75 '(&y, &x)': (&{unknown}, &{unknown}) + 68..70 '&y': &{unknown} + 69..70 'y': {unknown} + 72..74 '&x': &{unknown} + 73..74 'x': {unknown} "#]], ); } @@ -165,7 +163,6 @@ fn infer_std_crash_1() { #[test] fn infer_std_crash_2() { - cov_mark::check!(type_var_resolves_to_int_var); // caused "equating two type variables, ...", taken from std check_infer( r#" @@ -257,27 +254,27 @@ fn infer_std_crash_5() { expect![[r#" 26..322 '{ ... } }': () 32..320 'for co... }': () - 36..43 'content': &{unknown} + 36..43 'content': {unknown} 47..60 'doesnt_matter': {unknown} 61..320 '{ ... }': () - 75..79 'name': &&{unknown} - 82..166 'if doe... }': &&{unknown} + 75..79 'name': &{unknown} + 82..166 'if doe... }': &{unknown} 85..98 'doesnt_matter': bool - 99..128 '{ ... }': &&{unknown} - 113..118 'first': &&{unknown} - 134..166 '{ ... }': &&{unknown} - 148..156 '&content': &&{unknown} - 149..156 'content': &{unknown} + 99..128 '{ ... }': &{unknown} + 113..118 'first': &{unknown} + 134..166 '{ ... }': &{unknown} + 148..156 '&content': &{unknown} + 149..156 'content': {unknown} 181..188 'content': &{unknown} 191..313 'if ICE... }': &{unknown} 194..231 'ICE_RE..._VALUE': {unknown} 194..247 'ICE_RE...&name)': bool - 241..246 '&name': &&&{unknown} - 242..246 'name': &&{unknown} - 248..276 '{ ... }': &&{unknown} - 262..266 'name': &&{unknown} - 282..313 '{ ... }': &{unknown} - 296..303 'content': &{unknown} + 241..246 '&name': &&{unknown} + 242..246 'name': &{unknown} + 248..276 '{ ... }': &{unknown} + 262..266 'name': &{unknown} + 282..313 '{ ... }': {unknown} + 296..303 'content': {unknown} "#]], ); } @@ -761,7 +758,7 @@ fn issue_4885() { "#, expect![[r#" 136..139 'key': &K - 198..214 '{ ...key) }': impl Future>::Bar> + 198..214 '{ ...key) }': {unknown} 204..207 'bar': fn bar(&K) -> impl Future>::Bar> 204..212 'bar(key)': impl Future>::Bar> 208..211 'key': &K -- cgit v1.2.3 From a09079f27aa631b011f6c0703200862d28af81f4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 15 May 2021 16:00:24 +0200 Subject: Fix coercion of two closures to a function pointer Fixes #8604. --- crates/hir_ty/src/tests/coercion.rs | 17 ++++++++++++++++- crates/hir_ty/src/tests/simple.rs | 36 ------------------------------------ 2 files changed, 16 insertions(+), 37 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 190471069..67295b663 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -1,6 +1,6 @@ use expect_test::expect; -use super::{check_infer, check_infer_with_mismatches}; +use super::{check_infer, check_infer_with_mismatches, check_types}; #[test] fn infer_block_expr_type_mismatch() { @@ -858,3 +858,18 @@ fn coerce_unsize_generic() { "]], ); } + +#[test] +fn infer_two_closures_lub() { + check_types( + r#" +fn foo(c: i32) { + let add = |a: i32, b: i32| a + b; + let sub = |a, b| a - b; + //^ |i32, i32| -> i32 + if c > 42 { add } else { sub }; + //^ fn(i32, i32) -> i32 +} + "#, + ) +} diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index a9cd42186..5c70a1fc0 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs @@ -1039,42 +1039,6 @@ fn infer_in_elseif() { ) } -#[test] -fn infer_closure_unify() { - check_infer( - r#" - fn foo(f: bool) { - let a = |x| x; - let b = |x| x; - let id = if f { a } else { b }; - id(123); - } - "#, - expect![[r#" - 7..8 'f': bool - 16..106 '{ ...23); }': () - 26..27 'a': |i32| -> i32 - 30..35 '|x| x': |i32| -> i32 - 31..32 'x': i32 - 34..35 'x': i32 - 45..46 'b': |i32| -> i32 - 49..54 '|x| x': |i32| -> i32 - 50..51 'x': i32 - 53..54 'x': i32 - 64..66 'id': |i32| -> i32 - 69..90 'if f {... { b }': |i32| -> i32 - 72..73 'f': bool - 74..79 '{ a }': |i32| -> i32 - 76..77 'a': |i32| -> i32 - 85..90 '{ b }': |i32| -> i32 - 87..88 'b': |i32| -> i32 - 96..98 'id': |i32| -> i32 - 96..103 'id(123)': i32 - 99..102 '123': i32 - "#]], - ) -} - #[test] fn infer_if_match_with_return() { check_infer( -- cgit v1.2.3 From 32fc944263ae0b30eba130fbcf28f4eb5578fdb3 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 15 May 2021 17:01:27 +0200 Subject: Fix handling of diverging branches in match coercion Fixes #7626. --- crates/hir_ty/src/tests/coercion.rs | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 67295b663..bb568ea37 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -873,3 +873,42 @@ fn foo(c: i32) { "#, ) } + +#[test] +fn infer_match_diverging_branch_1() { + check_types( + r#" +enum Result { Ok(T), Err } +fn parse() -> T { loop {} } + +fn test() -> i32 { + let a = match parse() { + Ok(val) => val, + Err => return 0, + }; + a + //^ i32 +} + "#, + ) +} + +#[test] +fn infer_match_diverging_branch_2() { + // same as 1 except for order of branches + check_types( + r#" +enum Result { Ok(T), Err } +fn parse() -> T { loop {} } + +fn test() -> i32 { + let a = match parse() { + Err => return 0, + Ok(val) => val, + }; + a + //^ i32 +} + "#, + ) +} -- cgit v1.2.3 From 4bd446f5b3f8035d5db1fde1c6c50073e3f4fb2b Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 16 May 2021 17:56:38 +0200 Subject: Get rid of resolve_ty_as_possible Instead use shallow resolving where necessary. --- crates/hir_ty/src/tests/regression.rs | 16 ++++++++-------- crates/hir_ty/src/tests/traits.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 59a16f390..baef81590 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs @@ -117,19 +117,19 @@ fn recursive_vars_2() { "#, expect![[r#" 10..79 '{ ...x)]; }': () - 20..21 'x': {unknown} - 24..31 'unknown': {unknown} + 20..21 'x': &{unknown} + 24..31 'unknown': &{unknown} 41..42 'y': {unknown} 45..52 'unknown': {unknown} - 58..76 '[(x, y..., &x)]': [({unknown}, {unknown}); 2] - 59..65 '(x, y)': ({unknown}, {unknown}) - 60..61 'x': {unknown} + 58..76 '[(x, y..., &x)]': [(&{unknown}, {unknown}); 2] + 59..65 '(x, y)': (&{unknown}, {unknown}) + 60..61 'x': &{unknown} 63..64 'y': {unknown} - 67..75 '(&y, &x)': (&{unknown}, &{unknown}) + 67..75 '(&y, &x)': (&{unknown}, {unknown}) 68..70 '&y': &{unknown} 69..70 'y': {unknown} - 72..74 '&x': &{unknown} - 73..74 'x': {unknown} + 72..74 '&x': &&{unknown} + 73..74 'x': &{unknown} "#]], ); } diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index f80cf9879..a5a2df54c 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -3104,7 +3104,7 @@ fn foo() { 568..573 'f(&s)': FnOnce::Output), (&Option,)> 570..572 '&s': &Option 571..572 's': Option - 549..562: expected Box)>, got Box<|_| -> ()> + 549..562: expected Box)>, got Box<|{unknown}| -> ()> "#]], ); } -- cgit v1.2.3 From 9716c0b949b1a1a95b3f36928faed3abc21c0bda Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 16 May 2021 18:27:17 +0200 Subject: Deal with goals arising from unification --- crates/hir_ty/src/tests/regression.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index baef81590..ad9edf11c 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs @@ -758,7 +758,7 @@ fn issue_4885() { "#, expect![[r#" 136..139 'key': &K - 198..214 '{ ...key) }': {unknown} + 198..214 '{ ...key) }': impl Future>::Bar> 204..207 'bar': fn bar(&K) -> impl Future>::Bar> 204..212 'bar(key)': impl Future>::Bar> 208..211 'key': &K -- cgit v1.2.3 From e9d1550001f79390284cf7f0e958981f387a0c58 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 21 May 2021 18:07:30 +0200 Subject: Fix test after rebase --- crates/hir_ty/src/tests/patterns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index ddbadbe40..cd08b5c7a 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs @@ -747,7 +747,7 @@ fn foo(tuple: (u8, i16, f32)) { 209..210 '_': (u8, i16, f32) 214..216 '{}': () 136..142: expected (u8, i16, f32), got (u8, i16) - 170..182: expected (u8, i16, f32), got (u8, i16, f32, _) + 170..182: expected (u8, i16, f32), got (u8, i16, f32, {unknown}) "#]], ); } -- cgit v1.2.3