aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r--crates/hir_ty/src/tests/coercion.rs17
-rw-r--r--crates/hir_ty/src/tests/simple.rs36
2 files changed, 16 insertions, 37 deletions
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 @@
1use expect_test::expect; 1use expect_test::expect;
2 2
3use super::{check_infer, check_infer_with_mismatches}; 3use super::{check_infer, check_infer_with_mismatches, check_types};
4 4
5#[test] 5#[test]
6fn infer_block_expr_type_mismatch() { 6fn infer_block_expr_type_mismatch() {
@@ -858,3 +858,18 @@ fn coerce_unsize_generic() {
858 "]], 858 "]],
859 ); 859 );
860} 860}
861
862#[test]
863fn infer_two_closures_lub() {
864 check_types(
865 r#"
866fn foo(c: i32) {
867 let add = |a: i32, b: i32| a + b;
868 let sub = |a, b| a - b;
869 //^ |i32, i32| -> i32
870 if c > 42 { add } else { sub };
871 //^ fn(i32, i32) -> i32
872}
873 "#,
874 )
875}
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
@@ -1040,42 +1040,6 @@ fn infer_in_elseif() {
1040} 1040}
1041 1041
1042#[test] 1042#[test]
1043fn infer_closure_unify() {
1044 check_infer(
1045 r#"
1046 fn foo(f: bool) {
1047 let a = |x| x;
1048 let b = |x| x;
1049 let id = if f { a } else { b };
1050 id(123);
1051 }
1052 "#,
1053 expect![[r#"
1054 7..8 'f': bool
1055 16..106 '{ ...23); }': ()
1056 26..27 'a': |i32| -> i32
1057 30..35 '|x| x': |i32| -> i32
1058 31..32 'x': i32
1059 34..35 'x': i32
1060 45..46 'b': |i32| -> i32
1061 49..54 '|x| x': |i32| -> i32
1062 50..51 'x': i32
1063 53..54 'x': i32
1064 64..66 'id': |i32| -> i32
1065 69..90 'if f {... { b }': |i32| -> i32
1066 72..73 'f': bool
1067 74..79 '{ a }': |i32| -> i32
1068 76..77 'a': |i32| -> i32
1069 85..90 '{ b }': |i32| -> i32
1070 87..88 'b': |i32| -> i32
1071 96..98 'id': |i32| -> i32
1072 96..103 'id(123)': i32
1073 99..102 '123': i32
1074 "#]],
1075 )
1076}
1077
1078#[test]
1079fn infer_if_match_with_return() { 1043fn infer_if_match_with_return() {
1080 check_infer( 1044 check_infer(
1081 r#" 1045 r#"