aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorComonad <[email protected]>2021-04-29 08:26:41 +0100
committerComonad <[email protected]>2021-04-29 08:26:41 +0100
commit78f1583bdd0cc3d7adb65be6441db52e75e17060 (patch)
tree9f211591a2055c4820de7b92f5ad7d1aeb06a607 /crates
parentdce0d71b18ed78f55989d2a7462ae1d8df10e14f (diff)
fix: closure unify without check ClosureId
closes #8604
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/infer/unify.rs4
-rw-r--r--crates/hir_ty/src/tests/simple.rs36
2 files changed, 40 insertions, 0 deletions
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index a887e20b0..d8e0b4320 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -332,6 +332,10 @@ impl InferenceTable {
332 | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1), 332 | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1),
333 _ => true, /* we checked equals_ctor already */ 333 _ => true, /* we checked equals_ctor already */
334 } 334 }
335 } else if let (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) =
336 (ty1.kind(&Interner), ty2.kind(&Interner))
337 {
338 self.unify_substs(substs1, substs2, depth + 1)
335 } else { 339 } else {
336 self.unify_inner_trivial(&ty1, &ty2, depth) 340 self.unify_inner_trivial(&ty1, &ty2, depth)
337 } 341 }
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index 5948d0bc2..0eefd70f2 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -1029,6 +1029,42 @@ fn infer_in_elseif() {
1029} 1029}
1030 1030
1031#[test] 1031#[test]
1032fn infer_closure_unify() {
1033 check_infer(
1034 r#"
1035 fn foo(f: bool) {
1036 let a = |x| x;
1037 let b = |x| x;
1038 let id = if f { a } else { b };
1039 id(123);
1040 }
1041 "#,
1042 expect![[r#"
1043 7..8 'f': bool
1044 16..106 '{ ...23); }': ()
1045 26..27 'a': |i32| -> i32
1046 30..35 '|x| x': |i32| -> i32
1047 31..32 'x': i32
1048 34..35 'x': i32
1049 45..46 'b': |i32| -> i32
1050 49..54 '|x| x': |i32| -> i32
1051 50..51 'x': i32
1052 53..54 'x': i32
1053 64..66 'id': |i32| -> i32
1054 69..90 'if f {... { b }': |i32| -> i32
1055 72..73 'f': bool
1056 74..79 '{ a }': |i32| -> i32
1057 76..77 'a': |i32| -> i32
1058 85..90 '{ b }': |i32| -> i32
1059 87..88 'b': |i32| -> i32
1060 96..98 'id': |i32| -> i32
1061 96..103 'id(123)': i32
1062 99..102 '123': i32
1063 "#]],
1064 )
1065}
1066
1067#[test]
1032fn infer_if_match_with_return() { 1068fn infer_if_match_with_return() {
1033 check_infer( 1069 check_infer(
1034 r#" 1070 r#"