diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/coercion.rs | 56 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/patterns.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 69 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 36 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 2 |
5 files changed, 90 insertions, 75 deletions
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 190471069..bb568ea37 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use expect_test::expect; | 1 | use expect_test::expect; |
2 | 2 | ||
3 | use super::{check_infer, check_infer_with_mismatches}; | 3 | use super::{check_infer, check_infer_with_mismatches, check_types}; |
4 | 4 | ||
5 | #[test] | 5 | #[test] |
6 | fn infer_block_expr_type_mismatch() { | 6 | fn infer_block_expr_type_mismatch() { |
@@ -858,3 +858,57 @@ fn coerce_unsize_generic() { | |||
858 | "]], | 858 | "]], |
859 | ); | 859 | ); |
860 | } | 860 | } |
861 | |||
862 | #[test] | ||
863 | fn infer_two_closures_lub() { | ||
864 | check_types( | ||
865 | r#" | ||
866 | fn 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 | } | ||
876 | |||
877 | #[test] | ||
878 | fn infer_match_diverging_branch_1() { | ||
879 | check_types( | ||
880 | r#" | ||
881 | enum Result<T> { Ok(T), Err } | ||
882 | fn parse<T>() -> T { loop {} } | ||
883 | |||
884 | fn test() -> i32 { | ||
885 | let a = match parse() { | ||
886 | Ok(val) => val, | ||
887 | Err => return 0, | ||
888 | }; | ||
889 | a | ||
890 | //^ i32 | ||
891 | } | ||
892 | "#, | ||
893 | ) | ||
894 | } | ||
895 | |||
896 | #[test] | ||
897 | fn infer_match_diverging_branch_2() { | ||
898 | // same as 1 except for order of branches | ||
899 | check_types( | ||
900 | r#" | ||
901 | enum Result<T> { Ok(T), Err } | ||
902 | fn parse<T>() -> T { loop {} } | ||
903 | |||
904 | fn test() -> i32 { | ||
905 | let a = match parse() { | ||
906 | Err => return 0, | ||
907 | Ok(val) => val, | ||
908 | }; | ||
909 | a | ||
910 | //^ i32 | ||
911 | } | ||
912 | "#, | ||
913 | ) | ||
914 | } | ||
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)) { | |||
747 | 209..210 '_': (u8, i16, f32) | 747 | 209..210 '_': (u8, i16, f32) |
748 | 214..216 '{}': () | 748 | 214..216 '{}': () |
749 | 136..142: expected (u8, i16, f32), got (u8, i16) | 749 | 136..142: expected (u8, i16, f32), got (u8, i16) |
750 | 170..182: expected (u8, i16, f32), got (u8, i16, f32, _) | 750 | 170..182: expected (u8, i16, f32), got (u8, i16, f32, {unknown}) |
751 | "#]], | 751 | "#]], |
752 | ); | 752 | ); |
753 | } | 753 | } |
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 431861712..ad9edf11c 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -86,8 +86,6 @@ fn bug_651() { | |||
86 | 86 | ||
87 | #[test] | 87 | #[test] |
88 | fn recursive_vars() { | 88 | fn recursive_vars() { |
89 | cov_mark::check!(type_var_cycles_resolve_completely); | ||
90 | cov_mark::check!(type_var_cycles_resolve_as_possible); | ||
91 | check_infer( | 89 | check_infer( |
92 | r#" | 90 | r#" |
93 | fn test() { | 91 | fn test() { |
@@ -97,12 +95,12 @@ fn recursive_vars() { | |||
97 | "#, | 95 | "#, |
98 | expect![[r#" | 96 | expect![[r#" |
99 | 10..47 '{ ...&y]; }': () | 97 | 10..47 '{ ...&y]; }': () |
100 | 20..21 'y': &{unknown} | 98 | 20..21 'y': {unknown} |
101 | 24..31 'unknown': &{unknown} | 99 | 24..31 'unknown': {unknown} |
102 | 37..44 '[y, &y]': [&&{unknown}; 2] | 100 | 37..44 '[y, &y]': [{unknown}; 2] |
103 | 38..39 'y': &{unknown} | 101 | 38..39 'y': {unknown} |
104 | 41..43 '&y': &&{unknown} | 102 | 41..43 '&y': &{unknown} |
105 | 42..43 'y': &{unknown} | 103 | 42..43 'y': {unknown} |
106 | "#]], | 104 | "#]], |
107 | ); | 105 | ); |
108 | } | 106 | } |
@@ -119,19 +117,19 @@ fn recursive_vars_2() { | |||
119 | "#, | 117 | "#, |
120 | expect![[r#" | 118 | expect![[r#" |
121 | 10..79 '{ ...x)]; }': () | 119 | 10..79 '{ ...x)]; }': () |
122 | 20..21 'x': &&{unknown} | 120 | 20..21 'x': &{unknown} |
123 | 24..31 'unknown': &&{unknown} | 121 | 24..31 'unknown': &{unknown} |
124 | 41..42 'y': &&{unknown} | 122 | 41..42 'y': {unknown} |
125 | 45..52 'unknown': &&{unknown} | 123 | 45..52 'unknown': {unknown} |
126 | 58..76 '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown}); 2] | 124 | 58..76 '[(x, y..., &x)]': [(&{unknown}, {unknown}); 2] |
127 | 59..65 '(x, y)': (&&&{unknown}, &&&{unknown}) | 125 | 59..65 '(x, y)': (&{unknown}, {unknown}) |
128 | 60..61 'x': &&{unknown} | 126 | 60..61 'x': &{unknown} |
129 | 63..64 'y': &&{unknown} | 127 | 63..64 'y': {unknown} |
130 | 67..75 '(&y, &x)': (&&&{unknown}, &&&{unknown}) | 128 | 67..75 '(&y, &x)': (&{unknown}, {unknown}) |
131 | 68..70 '&y': &&&{unknown} | 129 | 68..70 '&y': &{unknown} |
132 | 69..70 'y': &&{unknown} | 130 | 69..70 'y': {unknown} |
133 | 72..74 '&x': &&&{unknown} | 131 | 72..74 '&x': &&{unknown} |
134 | 73..74 'x': &&{unknown} | 132 | 73..74 'x': &{unknown} |
135 | "#]], | 133 | "#]], |
136 | ); | 134 | ); |
137 | } | 135 | } |
@@ -165,7 +163,6 @@ fn infer_std_crash_1() { | |||
165 | 163 | ||
166 | #[test] | 164 | #[test] |
167 | fn infer_std_crash_2() { | 165 | fn infer_std_crash_2() { |
168 | cov_mark::check!(type_var_resolves_to_int_var); | ||
169 | // caused "equating two type variables, ...", taken from std | 166 | // caused "equating two type variables, ...", taken from std |
170 | check_infer( | 167 | check_infer( |
171 | r#" | 168 | r#" |
@@ -257,27 +254,27 @@ fn infer_std_crash_5() { | |||
257 | expect![[r#" | 254 | expect![[r#" |
258 | 26..322 '{ ... } }': () | 255 | 26..322 '{ ... } }': () |
259 | 32..320 'for co... }': () | 256 | 32..320 'for co... }': () |
260 | 36..43 'content': &{unknown} | 257 | 36..43 'content': {unknown} |
261 | 47..60 'doesnt_matter': {unknown} | 258 | 47..60 'doesnt_matter': {unknown} |
262 | 61..320 '{ ... }': () | 259 | 61..320 '{ ... }': () |
263 | 75..79 'name': &&{unknown} | 260 | 75..79 'name': &{unknown} |
264 | 82..166 'if doe... }': &&{unknown} | 261 | 82..166 'if doe... }': &{unknown} |
265 | 85..98 'doesnt_matter': bool | 262 | 85..98 'doesnt_matter': bool |
266 | 99..128 '{ ... }': &&{unknown} | 263 | 99..128 '{ ... }': &{unknown} |
267 | 113..118 'first': &&{unknown} | 264 | 113..118 'first': &{unknown} |
268 | 134..166 '{ ... }': &&{unknown} | 265 | 134..166 '{ ... }': &{unknown} |
269 | 148..156 '&content': &&{unknown} | 266 | 148..156 '&content': &{unknown} |
270 | 149..156 'content': &{unknown} | 267 | 149..156 'content': {unknown} |
271 | 181..188 'content': &{unknown} | 268 | 181..188 'content': &{unknown} |
272 | 191..313 'if ICE... }': &{unknown} | 269 | 191..313 'if ICE... }': &{unknown} |
273 | 194..231 'ICE_RE..._VALUE': {unknown} | 270 | 194..231 'ICE_RE..._VALUE': {unknown} |
274 | 194..247 'ICE_RE...&name)': bool | 271 | 194..247 'ICE_RE...&name)': bool |
275 | 241..246 '&name': &&&{unknown} | 272 | 241..246 '&name': &&{unknown} |
276 | 242..246 'name': &&{unknown} | 273 | 242..246 'name': &{unknown} |
277 | 248..276 '{ ... }': &&{unknown} | 274 | 248..276 '{ ... }': &{unknown} |
278 | 262..266 'name': &&{unknown} | 275 | 262..266 'name': &{unknown} |
279 | 282..313 '{ ... }': &{unknown} | 276 | 282..313 '{ ... }': {unknown} |
280 | 296..303 'content': &{unknown} | 277 | 296..303 'content': {unknown} |
281 | "#]], | 278 | "#]], |
282 | ); | 279 | ); |
283 | } | 280 | } |
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] |
1043 | fn 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] | ||
1079 | fn infer_if_match_with_return() { | 1043 | fn infer_if_match_with_return() { |
1080 | check_infer( | 1044 | check_infer( |
1081 | r#" | 1045 | r#" |
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() { | |||
3104 | 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)> | 3104 | 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)> |
3105 | 570..572 '&s': &Option<i32> | 3105 | 570..572 '&s': &Option<i32> |
3106 | 571..572 's': Option<i32> | 3106 | 571..572 's': Option<i32> |
3107 | 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|_| -> ()> | 3107 | 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> |
3108 | "#]], | 3108 | "#]], |
3109 | ); | 3109 | ); |
3110 | } | 3110 | } |