diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-21 11:36:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-21 11:36:04 +0100 |
commit | 9307c7f36396c4429bea434608cb5643135ae49d (patch) | |
tree | dae0469fcd4a29b480dd2332b58f9941c96a59a5 /crates/ra_hir_ty/src/tests/patterns.rs | |
parent | 9518e2f9d69dbb4a9ddd4a8bab87cf16a41fca03 (diff) | |
parent | daab8b2fd03340ea0be91281673c256b02ad8a90 (diff) |
Merge #5472
5472: Replace insta with expect r=matklad a=lnicola
Co-authored-by: Laurențiu Nicola <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests/patterns.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/patterns.rs | 1102 |
1 files changed, 552 insertions, 550 deletions
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index f937426bd..39fabf7eb 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs | |||
@@ -1,561 +1,561 @@ | |||
1 | use insta::assert_snapshot; | 1 | use expect::expect; |
2 | use test_utils::mark; | 2 | use test_utils::mark; |
3 | 3 | ||
4 | use super::{infer, infer_with_mismatches}; | 4 | use super::{check_infer, check_infer_with_mismatches}; |
5 | 5 | ||
6 | #[test] | 6 | #[test] |
7 | fn infer_pattern() { | 7 | fn infer_pattern() { |
8 | assert_snapshot!( | 8 | check_infer( |
9 | infer(r#" | 9 | r#" |
10 | fn test(x: &i32) { | 10 | fn test(x: &i32) { |
11 | let y = x; | 11 | let y = x; |
12 | let &z = x; | 12 | let &z = x; |
13 | let a = z; | 13 | let a = z; |
14 | let (c, d) = (1, "hello"); | 14 | let (c, d) = (1, "hello"); |
15 | 15 | ||
16 | for (e, f) in some_iter { | 16 | for (e, f) in some_iter { |
17 | let g = e; | 17 | let g = e; |
18 | } | 18 | } |
19 | 19 | ||
20 | if let [val] = opt { | 20 | if let [val] = opt { |
21 | let h = val; | 21 | let h = val; |
22 | } | 22 | } |
23 | 23 | ||
24 | let lambda = |a: u64, b, c: i32| { a + b; c }; | 24 | let lambda = |a: u64, b, c: i32| { a + b; c }; |
25 | 25 | ||
26 | let ref ref_to_x = x; | 26 | let ref ref_to_x = x; |
27 | let mut mut_x = x; | 27 | let mut mut_x = x; |
28 | let ref mut mut_ref_to_x = x; | 28 | let ref mut mut_ref_to_x = x; |
29 | let k = mut_ref_to_x; | 29 | let k = mut_ref_to_x; |
30 | } | 30 | } |
31 | "#), | 31 | "#, |
32 | @r###" | 32 | expect![[r#" |
33 | 8..9 'x': &i32 | 33 | 8..9 'x': &i32 |
34 | 17..368 '{ ...o_x; }': () | 34 | 17..368 '{ ...o_x; }': () |
35 | 27..28 'y': &i32 | 35 | 27..28 'y': &i32 |
36 | 31..32 'x': &i32 | 36 | 31..32 'x': &i32 |
37 | 42..44 '&z': &i32 | 37 | 42..44 '&z': &i32 |
38 | 43..44 'z': i32 | 38 | 43..44 'z': i32 |
39 | 47..48 'x': &i32 | 39 | 47..48 'x': &i32 |
40 | 58..59 'a': i32 | 40 | 58..59 'a': i32 |
41 | 62..63 'z': i32 | 41 | 62..63 'z': i32 |
42 | 73..79 '(c, d)': (i32, &str) | 42 | 73..79 '(c, d)': (i32, &str) |
43 | 74..75 'c': i32 | 43 | 74..75 'c': i32 |
44 | 77..78 'd': &str | 44 | 77..78 'd': &str |
45 | 82..94 '(1, "hello")': (i32, &str) | 45 | 82..94 '(1, "hello")': (i32, &str) |
46 | 83..84 '1': i32 | 46 | 83..84 '1': i32 |
47 | 86..93 '"hello"': &str | 47 | 86..93 '"hello"': &str |
48 | 101..151 'for (e... }': () | 48 | 101..151 'for (e... }': () |
49 | 105..111 '(e, f)': ({unknown}, {unknown}) | 49 | 105..111 '(e, f)': ({unknown}, {unknown}) |
50 | 106..107 'e': {unknown} | 50 | 106..107 'e': {unknown} |
51 | 109..110 'f': {unknown} | 51 | 109..110 'f': {unknown} |
52 | 115..124 'some_iter': {unknown} | 52 | 115..124 'some_iter': {unknown} |
53 | 125..151 '{ ... }': () | 53 | 125..151 '{ ... }': () |
54 | 139..140 'g': {unknown} | 54 | 139..140 'g': {unknown} |
55 | 143..144 'e': {unknown} | 55 | 143..144 'e': {unknown} |
56 | 157..204 'if let... }': () | 56 | 157..204 'if let... }': () |
57 | 164..169 '[val]': [{unknown}] | 57 | 164..169 '[val]': [{unknown}] |
58 | 165..168 'val': {unknown} | 58 | 165..168 'val': {unknown} |
59 | 172..175 'opt': [{unknown}] | 59 | 172..175 'opt': [{unknown}] |
60 | 176..204 '{ ... }': () | 60 | 176..204 '{ ... }': () |
61 | 190..191 'h': {unknown} | 61 | 190..191 'h': {unknown} |
62 | 194..197 'val': {unknown} | 62 | 194..197 'val': {unknown} |
63 | 214..220 'lambda': |u64, u64, i32| -> i32 | 63 | 214..220 'lambda': |u64, u64, i32| -> i32 |
64 | 223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32 | 64 | 223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32 |
65 | 224..225 'a': u64 | 65 | 224..225 'a': u64 |
66 | 232..233 'b': u64 | 66 | 232..233 'b': u64 |
67 | 235..236 'c': i32 | 67 | 235..236 'c': i32 |
68 | 243..255 '{ a + b; c }': i32 | 68 | 243..255 '{ a + b; c }': i32 |
69 | 245..246 'a': u64 | 69 | 245..246 'a': u64 |
70 | 245..250 'a + b': u64 | 70 | 245..250 'a + b': u64 |
71 | 249..250 'b': u64 | 71 | 249..250 'b': u64 |
72 | 252..253 'c': i32 | 72 | 252..253 'c': i32 |
73 | 266..278 'ref ref_to_x': &&i32 | 73 | 266..278 'ref ref_to_x': &&i32 |
74 | 281..282 'x': &i32 | 74 | 281..282 'x': &i32 |
75 | 292..301 'mut mut_x': &i32 | 75 | 292..301 'mut mut_x': &i32 |
76 | 304..305 'x': &i32 | 76 | 304..305 'x': &i32 |
77 | 315..335 'ref mu...f_to_x': &mut &i32 | 77 | 315..335 'ref mu...f_to_x': &mut &i32 |
78 | 338..339 'x': &i32 | 78 | 338..339 'x': &i32 |
79 | 349..350 'k': &mut &i32 | 79 | 349..350 'k': &mut &i32 |
80 | 353..365 'mut_ref_to_x': &mut &i32 | 80 | 353..365 'mut_ref_to_x': &mut &i32 |
81 | "### | 81 | "#]], |
82 | ); | 82 | ); |
83 | } | 83 | } |
84 | 84 | ||
85 | #[test] | 85 | #[test] |
86 | fn infer_literal_pattern() { | 86 | fn infer_literal_pattern() { |
87 | assert_snapshot!( | 87 | check_infer_with_mismatches( |
88 | infer_with_mismatches(r#" | 88 | r#" |
89 | fn any<T>() -> T { loop {} } | 89 | fn any<T>() -> T { loop {} } |
90 | fn test(x: &i32) { | 90 | fn test(x: &i32) { |
91 | if let "foo" = any() {} | 91 | if let "foo" = any() {} |
92 | if let 1 = any() {} | 92 | if let 1 = any() {} |
93 | if let 1u32 = any() {} | 93 | if let 1u32 = any() {} |
94 | if let 1f32 = any() {} | 94 | if let 1f32 = any() {} |
95 | if let 1.0 = any() {} | 95 | if let 1.0 = any() {} |
96 | if let true = any() {} | 96 | if let true = any() {} |
97 | } | 97 | } |
98 | "#, true), | 98 | "#, |
99 | @r###" | 99 | expect![[r#" |
100 | 17..28 '{ loop {} }': T | 100 | 17..28 '{ loop {} }': T |
101 | 19..26 'loop {}': ! | 101 | 19..26 'loop {}': ! |
102 | 24..26 '{}': () | 102 | 24..26 '{}': () |
103 | 37..38 'x': &i32 | 103 | 37..38 'x': &i32 |
104 | 46..208 '{ ...) {} }': () | 104 | 46..208 '{ ...) {} }': () |
105 | 52..75 'if let...y() {}': () | 105 | 52..75 'if let...y() {}': () |
106 | 59..64 '"foo"': &str | 106 | 59..64 '"foo"': &str |
107 | 59..64 '"foo"': &str | 107 | 59..64 '"foo"': &str |
108 | 67..70 'any': fn any<&str>() -> &str | 108 | 67..70 'any': fn any<&str>() -> &str |
109 | 67..72 'any()': &str | 109 | 67..72 'any()': &str |
110 | 73..75 '{}': () | 110 | 73..75 '{}': () |
111 | 80..99 'if let...y() {}': () | 111 | 80..99 'if let...y() {}': () |
112 | 87..88 '1': i32 | 112 | 87..88 '1': i32 |
113 | 87..88 '1': i32 | 113 | 87..88 '1': i32 |
114 | 91..94 'any': fn any<i32>() -> i32 | 114 | 91..94 'any': fn any<i32>() -> i32 |
115 | 91..96 'any()': i32 | 115 | 91..96 'any()': i32 |
116 | 97..99 '{}': () | 116 | 97..99 '{}': () |
117 | 104..126 'if let...y() {}': () | 117 | 104..126 'if let...y() {}': () |
118 | 111..115 '1u32': u32 | 118 | 111..115 '1u32': u32 |
119 | 111..115 '1u32': u32 | 119 | 111..115 '1u32': u32 |
120 | 118..121 'any': fn any<u32>() -> u32 | 120 | 118..121 'any': fn any<u32>() -> u32 |
121 | 118..123 'any()': u32 | 121 | 118..123 'any()': u32 |
122 | 124..126 '{}': () | 122 | 124..126 '{}': () |
123 | 131..153 'if let...y() {}': () | 123 | 131..153 'if let...y() {}': () |
124 | 138..142 '1f32': f32 | 124 | 138..142 '1f32': f32 |
125 | 138..142 '1f32': f32 | 125 | 138..142 '1f32': f32 |
126 | 145..148 'any': fn any<f32>() -> f32 | 126 | 145..148 'any': fn any<f32>() -> f32 |
127 | 145..150 'any()': f32 | 127 | 145..150 'any()': f32 |
128 | 151..153 '{}': () | 128 | 151..153 '{}': () |
129 | 158..179 'if let...y() {}': () | 129 | 158..179 'if let...y() {}': () |
130 | 165..168 '1.0': f64 | 130 | 165..168 '1.0': f64 |
131 | 165..168 '1.0': f64 | 131 | 165..168 '1.0': f64 |
132 | 171..174 'any': fn any<f64>() -> f64 | 132 | 171..174 'any': fn any<f64>() -> f64 |
133 | 171..176 'any()': f64 | 133 | 171..176 'any()': f64 |
134 | 177..179 '{}': () | 134 | 177..179 '{}': () |
135 | 184..206 'if let...y() {}': () | 135 | 184..206 'if let...y() {}': () |
136 | 191..195 'true': bool | 136 | 191..195 'true': bool |
137 | 191..195 'true': bool | 137 | 191..195 'true': bool |
138 | 198..201 'any': fn any<bool>() -> bool | 138 | 198..201 'any': fn any<bool>() -> bool |
139 | 198..203 'any()': bool | 139 | 198..203 'any()': bool |
140 | 204..206 '{}': () | 140 | 204..206 '{}': () |
141 | "### | 141 | "#]], |
142 | ); | 142 | ); |
143 | } | 143 | } |
144 | 144 | ||
145 | #[test] | 145 | #[test] |
146 | fn infer_range_pattern() { | 146 | fn infer_range_pattern() { |
147 | assert_snapshot!( | 147 | check_infer_with_mismatches( |
148 | infer_with_mismatches(r#" | 148 | r#" |
149 | fn test(x: &i32) { | 149 | fn test(x: &i32) { |
150 | if let 1..76 = 2u32 {} | 150 | if let 1..76 = 2u32 {} |
151 | if let 1..=76 = 2u32 {} | 151 | if let 1..=76 = 2u32 {} |
152 | } | 152 | } |
153 | "#, true), | 153 | "#, |
154 | @r###" | 154 | expect![[r#" |
155 | 8..9 'x': &i32 | 155 | 8..9 'x': &i32 |
156 | 17..75 '{ ...2 {} }': () | 156 | 17..75 '{ ...2 {} }': () |
157 | 23..45 'if let...u32 {}': () | 157 | 23..45 'if let...u32 {}': () |
158 | 30..35 '1..76': u32 | 158 | 30..35 '1..76': u32 |
159 | 38..42 '2u32': u32 | 159 | 38..42 '2u32': u32 |
160 | 43..45 '{}': () | 160 | 43..45 '{}': () |
161 | 50..73 'if let...u32 {}': () | 161 | 50..73 'if let...u32 {}': () |
162 | 57..63 '1..=76': u32 | 162 | 57..63 '1..=76': u32 |
163 | 66..70 '2u32': u32 | 163 | 66..70 '2u32': u32 |
164 | 71..73 '{}': () | 164 | 71..73 '{}': () |
165 | "### | 165 | "#]], |
166 | ); | 166 | ); |
167 | } | 167 | } |
168 | 168 | ||
169 | #[test] | 169 | #[test] |
170 | fn infer_pattern_match_ergonomics() { | 170 | fn infer_pattern_match_ergonomics() { |
171 | assert_snapshot!( | 171 | check_infer( |
172 | infer(r#" | 172 | r#" |
173 | struct A<T>(T); | 173 | struct A<T>(T); |
174 | 174 | ||
175 | fn test() { | 175 | fn test() { |
176 | let A(n) = &A(1); | 176 | let A(n) = &A(1); |
177 | let A(n) = &mut A(1); | 177 | let A(n) = &mut A(1); |
178 | } | 178 | } |
179 | "#), | 179 | "#, |
180 | @r###" | 180 | expect![[r#" |
181 | 27..78 '{ ...(1); }': () | 181 | 27..78 '{ ...(1); }': () |
182 | 37..41 'A(n)': A<i32> | 182 | 37..41 'A(n)': A<i32> |
183 | 39..40 'n': &i32 | 183 | 39..40 'n': &i32 |
184 | 44..49 '&A(1)': &A<i32> | 184 | 44..49 '&A(1)': &A<i32> |
185 | 45..46 'A': A<i32>(i32) -> A<i32> | 185 | 45..46 'A': A<i32>(i32) -> A<i32> |
186 | 45..49 'A(1)': A<i32> | 186 | 45..49 'A(1)': A<i32> |
187 | 47..48 '1': i32 | 187 | 47..48 '1': i32 |
188 | 59..63 'A(n)': A<i32> | 188 | 59..63 'A(n)': A<i32> |
189 | 61..62 'n': &mut i32 | 189 | 61..62 'n': &mut i32 |
190 | 66..75 '&mut A(1)': &mut A<i32> | 190 | 66..75 '&mut A(1)': &mut A<i32> |
191 | 71..72 'A': A<i32>(i32) -> A<i32> | 191 | 71..72 'A': A<i32>(i32) -> A<i32> |
192 | 71..75 'A(1)': A<i32> | 192 | 71..75 'A(1)': A<i32> |
193 | 73..74 '1': i32 | 193 | 73..74 '1': i32 |
194 | "### | 194 | "#]], |
195 | ); | 195 | ); |
196 | } | 196 | } |
197 | 197 | ||
198 | #[test] | 198 | #[test] |
199 | fn infer_pattern_match_ergonomics_ref() { | 199 | fn infer_pattern_match_ergonomics_ref() { |
200 | mark::check!(match_ergonomics_ref); | 200 | mark::check!(match_ergonomics_ref); |
201 | assert_snapshot!( | 201 | check_infer( |
202 | infer(r#" | 202 | r#" |
203 | fn test() { | 203 | fn test() { |
204 | let v = &(1, &2); | 204 | let v = &(1, &2); |
205 | let (_, &w) = v; | 205 | let (_, &w) = v; |
206 | } | 206 | } |
207 | "#), | 207 | "#, |
208 | @r###" | 208 | expect![[r#" |
209 | 10..56 '{ ...= v; }': () | 209 | 10..56 '{ ...= v; }': () |
210 | 20..21 'v': &(i32, &i32) | 210 | 20..21 'v': &(i32, &i32) |
211 | 24..32 '&(1, &2)': &(i32, &i32) | 211 | 24..32 '&(1, &2)': &(i32, &i32) |
212 | 25..32 '(1, &2)': (i32, &i32) | 212 | 25..32 '(1, &2)': (i32, &i32) |
213 | 26..27 '1': i32 | 213 | 26..27 '1': i32 |
214 | 29..31 '&2': &i32 | 214 | 29..31 '&2': &i32 |
215 | 30..31 '2': i32 | 215 | 30..31 '2': i32 |
216 | 42..49 '(_, &w)': (i32, &i32) | 216 | 42..49 '(_, &w)': (i32, &i32) |
217 | 43..44 '_': i32 | 217 | 43..44 '_': i32 |
218 | 46..48 '&w': &i32 | 218 | 46..48 '&w': &i32 |
219 | 47..48 'w': i32 | 219 | 47..48 'w': i32 |
220 | 52..53 'v': &(i32, &i32) | 220 | 52..53 'v': &(i32, &i32) |
221 | "### | 221 | "#]], |
222 | ); | 222 | ); |
223 | } | 223 | } |
224 | 224 | ||
225 | #[test] | 225 | #[test] |
226 | fn infer_pattern_match_slice() { | 226 | fn infer_pattern_match_slice() { |
227 | assert_snapshot!( | 227 | check_infer( |
228 | infer(r#" | 228 | r#" |
229 | fn test() { | 229 | fn test() { |
230 | let slice: &[f64] = &[0.0]; | 230 | let slice: &[f64] = &[0.0]; |
231 | match slice { | 231 | match slice { |
232 | &[] => {}, | 232 | &[] => {}, |
233 | &[a] => { | 233 | &[a] => { |
234 | a; | 234 | a; |
235 | }, | 235 | }, |
236 | &[b, c] => { | 236 | &[b, c] => { |
237 | b; | 237 | b; |
238 | c; | 238 | c; |
239 | } | ||
240 | _ => {} | ||
241 | } | ||
239 | } | 242 | } |
240 | _ => {} | 243 | "#, |
241 | } | 244 | expect![[r#" |
242 | } | 245 | 10..209 '{ ... } }': () |
243 | "#), | 246 | 20..25 'slice': &[f64] |
244 | @r###" | 247 | 36..42 '&[0.0]': &[f64; _] |
245 | 10..209 '{ ... } }': () | 248 | 37..42 '[0.0]': [f64; _] |
246 | 20..25 'slice': &[f64] | 249 | 38..41 '0.0': f64 |
247 | 36..42 '&[0.0]': &[f64; _] | 250 | 48..207 'match ... }': () |
248 | 37..42 '[0.0]': [f64; _] | 251 | 54..59 'slice': &[f64] |
249 | 38..41 '0.0': f64 | 252 | 70..73 '&[]': &[f64] |
250 | 48..207 'match ... }': () | 253 | 71..73 '[]': [f64] |
251 | 54..59 'slice': &[f64] | 254 | 77..79 '{}': () |
252 | 70..73 '&[]': &[f64] | 255 | 89..93 '&[a]': &[f64] |
253 | 71..73 '[]': [f64] | 256 | 90..93 '[a]': [f64] |
254 | 77..79 '{}': () | 257 | 91..92 'a': f64 |
255 | 89..93 '&[a]': &[f64] | 258 | 97..123 '{ ... }': () |
256 | 90..93 '[a]': [f64] | 259 | 111..112 'a': f64 |
257 | 91..92 'a': f64 | 260 | 133..140 '&[b, c]': &[f64] |
258 | 97..123 '{ ... }': () | 261 | 134..140 '[b, c]': [f64] |
259 | 111..112 'a': f64 | 262 | 135..136 'b': f64 |
260 | 133..140 '&[b, c]': &[f64] | 263 | 138..139 'c': f64 |
261 | 134..140 '[b, c]': [f64] | 264 | 144..185 '{ ... }': () |
262 | 135..136 'b': f64 | 265 | 158..159 'b': f64 |
263 | 138..139 'c': f64 | 266 | 173..174 'c': f64 |
264 | 144..185 '{ ... }': () | 267 | 194..195 '_': &[f64] |
265 | 158..159 'b': f64 | 268 | 199..201 '{}': () |
266 | 173..174 'c': f64 | 269 | "#]], |
267 | 194..195 '_': &[f64] | ||
268 | 199..201 '{}': () | ||
269 | "### | ||
270 | ); | 270 | ); |
271 | } | 271 | } |
272 | 272 | ||
273 | #[test] | 273 | #[test] |
274 | fn infer_pattern_match_string_literal() { | 274 | fn infer_pattern_match_string_literal() { |
275 | assert_snapshot!( | 275 | check_infer_with_mismatches( |
276 | infer_with_mismatches(r#" | 276 | r#" |
277 | fn test() { | 277 | fn test() { |
278 | let s: &str = "hello"; | 278 | let s: &str = "hello"; |
279 | match s { | 279 | match s { |
280 | "hello" => {} | 280 | "hello" => {} |
281 | _ => {} | 281 | _ => {} |
282 | } | 282 | } |
283 | } | 283 | } |
284 | "#, true), | 284 | "#, |
285 | @r###" | 285 | expect![[r#" |
286 | 10..98 '{ ... } }': () | 286 | 10..98 '{ ... } }': () |
287 | 20..21 's': &str | 287 | 20..21 's': &str |
288 | 30..37 '"hello"': &str | 288 | 30..37 '"hello"': &str |
289 | 43..96 'match ... }': () | 289 | 43..96 'match ... }': () |
290 | 49..50 's': &str | 290 | 49..50 's': &str |
291 | 61..68 '"hello"': &str | 291 | 61..68 '"hello"': &str |
292 | 61..68 '"hello"': &str | 292 | 61..68 '"hello"': &str |
293 | 72..74 '{}': () | 293 | 72..74 '{}': () |
294 | 83..84 '_': &str | 294 | 83..84 '_': &str |
295 | 88..90 '{}': () | 295 | 88..90 '{}': () |
296 | "### | 296 | "#]], |
297 | ); | 297 | ); |
298 | } | 298 | } |
299 | 299 | ||
300 | #[test] | 300 | #[test] |
301 | fn infer_pattern_match_or() { | 301 | fn infer_pattern_match_or() { |
302 | assert_snapshot!( | 302 | check_infer_with_mismatches( |
303 | infer_with_mismatches(r#" | 303 | r#" |
304 | fn test() { | 304 | fn test() { |
305 | let s: &str = "hello"; | 305 | let s: &str = "hello"; |
306 | match s { | 306 | match s { |
307 | "hello" | "world" => {} | 307 | "hello" | "world" => {} |
308 | _ => {} | 308 | _ => {} |
309 | } | 309 | } |
310 | } | 310 | } |
311 | "#, true), | 311 | "#, |
312 | @r###" | 312 | expect![[r#" |
313 | 10..108 '{ ... } }': () | 313 | 10..108 '{ ... } }': () |
314 | 20..21 's': &str | 314 | 20..21 's': &str |
315 | 30..37 '"hello"': &str | 315 | 30..37 '"hello"': &str |
316 | 43..106 'match ... }': () | 316 | 43..106 'match ... }': () |
317 | 49..50 's': &str | 317 | 49..50 's': &str |
318 | 61..68 '"hello"': &str | 318 | 61..68 '"hello"': &str |
319 | 61..68 '"hello"': &str | 319 | 61..68 '"hello"': &str |
320 | 61..78 '"hello...world"': &str | 320 | 61..78 '"hello...world"': &str |
321 | 71..78 '"world"': &str | 321 | 71..78 '"world"': &str |
322 | 71..78 '"world"': &str | 322 | 71..78 '"world"': &str |
323 | 82..84 '{}': () | 323 | 82..84 '{}': () |
324 | 93..94 '_': &str | 324 | 93..94 '_': &str |
325 | 98..100 '{}': () | 325 | 98..100 '{}': () |
326 | "### | 326 | "#]], |
327 | ); | 327 | ); |
328 | } | 328 | } |
329 | 329 | ||
330 | #[test] | 330 | #[test] |
331 | fn infer_pattern_match_arr() { | 331 | fn infer_pattern_match_arr() { |
332 | assert_snapshot!( | 332 | check_infer( |
333 | infer(r#" | 333 | r#" |
334 | fn test() { | 334 | fn test() { |
335 | let arr: [f64; 2] = [0.0, 1.0]; | 335 | let arr: [f64; 2] = [0.0, 1.0]; |
336 | match arr { | 336 | match arr { |
337 | [1.0, a] => { | 337 | [1.0, a] => { |
338 | a; | 338 | a; |
339 | }, | 339 | }, |
340 | [b, c] => { | 340 | [b, c] => { |
341 | b; | 341 | b; |
342 | c; | 342 | c; |
343 | } | ||
344 | } | ||
343 | } | 345 | } |
344 | } | 346 | "#, |
345 | } | 347 | expect![[r#" |
346 | "#), | 348 | 10..179 '{ ... } }': () |
347 | @r###" | 349 | 20..23 'arr': [f64; _] |
348 | 10..179 '{ ... } }': () | 350 | 36..46 '[0.0, 1.0]': [f64; _] |
349 | 20..23 'arr': [f64; _] | 351 | 37..40 '0.0': f64 |
350 | 36..46 '[0.0, 1.0]': [f64; _] | 352 | 42..45 '1.0': f64 |
351 | 37..40 '0.0': f64 | 353 | 52..177 'match ... }': () |
352 | 42..45 '1.0': f64 | 354 | 58..61 'arr': [f64; _] |
353 | 52..177 'match ... }': () | 355 | 72..80 '[1.0, a]': [f64; _] |
354 | 58..61 'arr': [f64; _] | 356 | 73..76 '1.0': f64 |
355 | 72..80 '[1.0, a]': [f64; _] | 357 | 73..76 '1.0': f64 |
356 | 73..76 '1.0': f64 | 358 | 78..79 'a': f64 |
357 | 73..76 '1.0': f64 | 359 | 84..110 '{ ... }': () |
358 | 78..79 'a': f64 | 360 | 98..99 'a': f64 |
359 | 84..110 '{ ... }': () | 361 | 120..126 '[b, c]': [f64; _] |
360 | 98..99 'a': f64 | 362 | 121..122 'b': f64 |
361 | 120..126 '[b, c]': [f64; _] | 363 | 124..125 'c': f64 |
362 | 121..122 'b': f64 | 364 | 130..171 '{ ... }': () |
363 | 124..125 'c': f64 | 365 | 144..145 'b': f64 |
364 | 130..171 '{ ... }': () | 366 | 159..160 'c': f64 |
365 | 144..145 'b': f64 | 367 | "#]], |
366 | 159..160 'c': f64 | ||
367 | "### | ||
368 | ); | 368 | ); |
369 | } | 369 | } |
370 | 370 | ||
371 | #[test] | 371 | #[test] |
372 | fn infer_adt_pattern() { | 372 | fn infer_adt_pattern() { |
373 | assert_snapshot!( | 373 | check_infer( |
374 | infer(r#" | 374 | r#" |
375 | enum E { | 375 | enum E { |
376 | A { x: usize }, | 376 | A { x: usize }, |
377 | B | 377 | B |
378 | } | 378 | } |
379 | 379 | ||
380 | struct S(u32, E); | 380 | struct S(u32, E); |
381 | 381 | ||
382 | fn test() { | 382 | fn test() { |
383 | let e = E::A { x: 3 }; | 383 | let e = E::A { x: 3 }; |
384 | 384 | ||
385 | let S(y, z) = foo; | 385 | let S(y, z) = foo; |
386 | let E::A { x: new_var } = e; | 386 | let E::A { x: new_var } = e; |
387 | 387 | ||
388 | match e { | 388 | match e { |
389 | E::A { x } => x, | 389 | E::A { x } => x, |
390 | E::B if foo => 1, | 390 | E::B if foo => 1, |
391 | E::B => 10, | 391 | E::B => 10, |
392 | }; | 392 | }; |
393 | 393 | ||
394 | let ref d @ E::A { .. } = e; | 394 | let ref d @ E::A { .. } = e; |
395 | d; | 395 | d; |
396 | } | 396 | } |
397 | "#), | 397 | "#, |
398 | @r###" | 398 | expect![[r#" |
399 | 67..288 '{ ... d; }': () | 399 | 67..288 '{ ... d; }': () |
400 | 77..78 'e': E | 400 | 77..78 'e': E |
401 | 81..94 'E::A { x: 3 }': E | 401 | 81..94 'E::A { x: 3 }': E |
402 | 91..92 '3': usize | 402 | 91..92 '3': usize |
403 | 105..112 'S(y, z)': S | 403 | 105..112 'S(y, z)': S |
404 | 107..108 'y': u32 | 404 | 107..108 'y': u32 |
405 | 110..111 'z': E | 405 | 110..111 'z': E |
406 | 115..118 'foo': S | 406 | 115..118 'foo': S |
407 | 128..147 'E::A {..._var }': E | 407 | 128..147 'E::A {..._var }': E |
408 | 138..145 'new_var': usize | 408 | 138..145 'new_var': usize |
409 | 150..151 'e': E | 409 | 150..151 'e': E |
410 | 158..244 'match ... }': usize | 410 | 158..244 'match ... }': usize |
411 | 164..165 'e': E | 411 | 164..165 'e': E |
412 | 176..186 'E::A { x }': E | 412 | 176..186 'E::A { x }': E |
413 | 183..184 'x': usize | 413 | 183..184 'x': usize |
414 | 190..191 'x': usize | 414 | 190..191 'x': usize |
415 | 201..205 'E::B': E | 415 | 201..205 'E::B': E |
416 | 209..212 'foo': bool | 416 | 209..212 'foo': bool |
417 | 216..217 '1': usize | 417 | 216..217 '1': usize |
418 | 227..231 'E::B': E | 418 | 227..231 'E::B': E |
419 | 235..237 '10': usize | 419 | 235..237 '10': usize |
420 | 255..274 'ref d ...{ .. }': &E | 420 | 255..274 'ref d ...{ .. }': &E |
421 | 263..274 'E::A { .. }': E | 421 | 263..274 'E::A { .. }': E |
422 | 277..278 'e': E | 422 | 277..278 'e': E |
423 | 284..285 'd': &E | 423 | 284..285 'd': &E |
424 | "### | 424 | "#]], |
425 | ); | 425 | ); |
426 | } | 426 | } |
427 | 427 | ||
428 | #[test] | 428 | #[test] |
429 | fn enum_variant_through_self_in_pattern() { | 429 | fn enum_variant_through_self_in_pattern() { |
430 | assert_snapshot!( | 430 | check_infer( |
431 | infer(r#" | 431 | r#" |
432 | enum E { | 432 | enum E { |
433 | A { x: usize }, | 433 | A { x: usize }, |
434 | B(usize), | 434 | B(usize), |
435 | C | 435 | C |
436 | } | 436 | } |
437 | 437 | ||
438 | impl E { | 438 | impl E { |
439 | fn test() { | 439 | fn test() { |
440 | match (loop {}) { | 440 | match (loop {}) { |
441 | Self::A { x } => { x; }, | 441 | Self::A { x } => { x; }, |
442 | Self::B(x) => { x; }, | 442 | Self::B(x) => { x; }, |
443 | Self::C => {}, | 443 | Self::C => {}, |
444 | }; | 444 | }; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | "#), | 447 | "#, |
448 | @r###" | 448 | expect![[r#" |
449 | 75..217 '{ ... }': () | 449 | 75..217 '{ ... }': () |
450 | 85..210 'match ... }': () | 450 | 85..210 'match ... }': () |
451 | 92..99 'loop {}': ! | 451 | 92..99 'loop {}': ! |
452 | 97..99 '{}': () | 452 | 97..99 '{}': () |
453 | 115..128 'Self::A { x }': E | 453 | 115..128 'Self::A { x }': E |
454 | 125..126 'x': usize | 454 | 125..126 'x': usize |
455 | 132..138 '{ x; }': () | 455 | 132..138 '{ x; }': () |
456 | 134..135 'x': usize | 456 | 134..135 'x': usize |
457 | 152..162 'Self::B(x)': E | 457 | 152..162 'Self::B(x)': E |
458 | 160..161 'x': usize | 458 | 160..161 'x': usize |
459 | 166..172 '{ x; }': () | 459 | 166..172 '{ x; }': () |
460 | 168..169 'x': usize | 460 | 168..169 'x': usize |
461 | 186..193 'Self::C': E | 461 | 186..193 'Self::C': E |
462 | 197..199 '{}': () | 462 | 197..199 '{}': () |
463 | "### | 463 | "#]], |
464 | ); | 464 | ); |
465 | } | 465 | } |
466 | 466 | ||
467 | #[test] | 467 | #[test] |
468 | fn infer_generics_in_patterns() { | 468 | fn infer_generics_in_patterns() { |
469 | assert_snapshot!( | 469 | check_infer( |
470 | infer(r#" | 470 | r#" |
471 | struct A<T> { | 471 | struct A<T> { |
472 | x: T, | 472 | x: T, |
473 | } | 473 | } |
474 | 474 | ||
475 | enum Option<T> { | 475 | enum Option<T> { |
476 | Some(T), | 476 | Some(T), |
477 | None, | 477 | None, |
478 | } | 478 | } |
479 | 479 | ||
480 | fn test(a1: A<u32>, o: Option<u64>) { | 480 | fn test(a1: A<u32>, o: Option<u64>) { |
481 | let A { x: x2 } = a1; | 481 | let A { x: x2 } = a1; |
482 | let A::<i64> { x: x3 } = A { x: 1 }; | 482 | let A::<i64> { x: x3 } = A { x: 1 }; |
483 | match o { | 483 | match o { |
484 | Option::Some(t) => t, | 484 | Option::Some(t) => t, |
485 | _ => 1, | 485 | _ => 1, |
486 | }; | 486 | }; |
487 | } | 487 | } |
488 | "#), | 488 | "#, |
489 | @r###" | 489 | expect![[r#" |
490 | 78..80 'a1': A<u32> | 490 | 78..80 'a1': A<u32> |
491 | 90..91 'o': Option<u64> | 491 | 90..91 'o': Option<u64> |
492 | 106..243 '{ ... }; }': () | 492 | 106..243 '{ ... }; }': () |
493 | 116..127 'A { x: x2 }': A<u32> | 493 | 116..127 'A { x: x2 }': A<u32> |
494 | 123..125 'x2': u32 | 494 | 123..125 'x2': u32 |
495 | 130..132 'a1': A<u32> | 495 | 130..132 'a1': A<u32> |
496 | 142..160 'A::<i6...: x3 }': A<i64> | 496 | 142..160 'A::<i6...: x3 }': A<i64> |
497 | 156..158 'x3': i64 | 497 | 156..158 'x3': i64 |
498 | 163..173 'A { x: 1 }': A<i64> | 498 | 163..173 'A { x: 1 }': A<i64> |
499 | 170..171 '1': i64 | 499 | 170..171 '1': i64 |
500 | 179..240 'match ... }': u64 | 500 | 179..240 'match ... }': u64 |
501 | 185..186 'o': Option<u64> | 501 | 185..186 'o': Option<u64> |
502 | 197..212 'Option::Some(t)': Option<u64> | 502 | 197..212 'Option::Some(t)': Option<u64> |
503 | 210..211 't': u64 | 503 | 210..211 't': u64 |
504 | 216..217 't': u64 | 504 | 216..217 't': u64 |
505 | 227..228 '_': Option<u64> | 505 | 227..228 '_': Option<u64> |
506 | 232..233 '1': u64 | 506 | 232..233 '1': u64 |
507 | "### | 507 | "#]], |
508 | ); | 508 | ); |
509 | } | 509 | } |
510 | 510 | ||
511 | #[test] | 511 | #[test] |
512 | fn infer_const_pattern() { | 512 | fn infer_const_pattern() { |
513 | assert_snapshot!( | 513 | check_infer_with_mismatches( |
514 | infer_with_mismatches(r#" | 514 | r#" |
515 | enum Option<T> { None } | 515 | enum Option<T> { None } |
516 | use Option::None; | 516 | use Option::None; |
517 | struct Foo; | 517 | struct Foo; |
518 | const Bar: usize = 1; | 518 | const Bar: usize = 1; |
519 | 519 | ||
520 | fn test() { | 520 | fn test() { |
521 | let a: Option<u32> = None; | 521 | let a: Option<u32> = None; |
522 | let b: Option<i64> = match a { | 522 | let b: Option<i64> = match a { |
523 | None => None, | 523 | None => None, |
524 | }; | 524 | }; |
525 | let _: () = match () { Foo => Foo }; // Expected mismatch | 525 | let _: () = match () { Foo => Foo }; // Expected mismatch |
526 | let _: () = match () { Bar => Bar }; // Expected mismatch | 526 | let _: () = match () { Bar => Bar }; // Expected mismatch |
527 | } | 527 | } |
528 | "#, true), | 528 | "#, |
529 | @r###" | 529 | expect![[r#" |
530 | 73..74 '1': usize | 530 | 73..74 '1': usize |
531 | 87..309 '{ ...atch }': () | 531 | 87..309 '{ ...atch }': () |
532 | 97..98 'a': Option<u32> | 532 | 97..98 'a': Option<u32> |
533 | 114..118 'None': Option<u32> | 533 | 114..118 'None': Option<u32> |
534 | 128..129 'b': Option<i64> | 534 | 128..129 'b': Option<i64> |
535 | 145..182 'match ... }': Option<i64> | 535 | 145..182 'match ... }': Option<i64> |
536 | 151..152 'a': Option<u32> | 536 | 151..152 'a': Option<u32> |
537 | 163..167 'None': Option<u32> | 537 | 163..167 'None': Option<u32> |
538 | 171..175 'None': Option<i64> | 538 | 171..175 'None': Option<i64> |
539 | 192..193 '_': () | 539 | 192..193 '_': () |
540 | 200..223 'match ... Foo }': Foo | 540 | 200..223 'match ... Foo }': Foo |
541 | 206..208 '()': () | 541 | 206..208 '()': () |
542 | 211..214 'Foo': Foo | 542 | 211..214 'Foo': Foo |
543 | 218..221 'Foo': Foo | 543 | 218..221 'Foo': Foo |
544 | 254..255 '_': () | 544 | 254..255 '_': () |
545 | 262..285 'match ... Bar }': usize | 545 | 262..285 'match ... Bar }': usize |
546 | 268..270 '()': () | 546 | 268..270 '()': () |
547 | 273..276 'Bar': usize | 547 | 273..276 'Bar': usize |
548 | 280..283 'Bar': usize | 548 | 280..283 'Bar': usize |
549 | 200..223: expected (), got Foo | 549 | 200..223: expected (), got Foo |
550 | 262..285: expected (), got usize | 550 | 262..285: expected (), got usize |
551 | "### | 551 | "#]], |
552 | ); | 552 | ); |
553 | } | 553 | } |
554 | 554 | ||
555 | #[test] | 555 | #[test] |
556 | fn infer_guard() { | 556 | fn infer_guard() { |
557 | assert_snapshot!( | 557 | check_infer( |
558 | infer(r#" | 558 | r#" |
559 | struct S; | 559 | struct S; |
560 | impl S { fn foo(&self) -> bool { false } } | 560 | impl S { fn foo(&self) -> bool { false } } |
561 | 561 | ||
@@ -564,91 +564,93 @@ fn main() { | |||
564 | s if s.foo() => (), | 564 | s if s.foo() => (), |
565 | } | 565 | } |
566 | } | 566 | } |
567 | "#), @r###" | 567 | "#, |
568 | 27..31 'self': &S | 568 | expect![[r#" |
569 | 41..50 '{ false }': bool | 569 | 27..31 'self': &S |
570 | 43..48 'false': bool | 570 | 41..50 '{ false }': bool |
571 | 64..115 '{ ... } }': () | 571 | 43..48 'false': bool |
572 | 70..113 'match ... }': () | 572 | 64..115 '{ ... } }': () |
573 | 76..77 'S': S | 573 | 70..113 'match ... }': () |
574 | 88..89 's': S | 574 | 76..77 'S': S |
575 | 93..94 's': S | 575 | 88..89 's': S |
576 | 93..100 's.foo()': bool | 576 | 93..94 's': S |
577 | 104..106 '()': () | 577 | 93..100 's.foo()': bool |
578 | "###) | 578 | 104..106 '()': () |
579 | "#]], | ||
580 | ) | ||
579 | } | 581 | } |
580 | 582 | ||
581 | #[test] | 583 | #[test] |
582 | fn match_ergonomics_in_closure_params() { | 584 | fn match_ergonomics_in_closure_params() { |
583 | assert_snapshot!( | 585 | check_infer( |
584 | infer(r#" | 586 | r#" |
585 | #[lang = "fn_once"] | 587 | #[lang = "fn_once"] |
586 | trait FnOnce<Args> { | 588 | trait FnOnce<Args> { |
587 | type Output; | 589 | type Output; |
588 | } | 590 | } |
589 | 591 | ||
590 | fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} } | 592 | fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} } |
591 | 593 | ||
592 | fn test() { | 594 | fn test() { |
593 | foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics | 595 | foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics |
594 | foo(&(1, "a"), |(x, y)| x); | 596 | foo(&(1, "a"), |(x, y)| x); |
595 | } | 597 | } |
596 | "#), | 598 | "#, |
597 | @r###" | 599 | expect![[r#" |
598 | 93..94 't': T | 600 | 93..94 't': T |
599 | 99..100 'f': F | 601 | 99..100 'f': F |
600 | 110..121 '{ loop {} }': U | 602 | 110..121 '{ loop {} }': U |
601 | 112..119 'loop {}': ! | 603 | 112..119 'loop {}': ! |
602 | 117..119 '{}': () | 604 | 117..119 '{}': () |
603 | 133..232 '{ ... x); }': () | 605 | 133..232 '{ ... x); }': () |
604 | 139..142 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32 | 606 | 139..142 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32 |
605 | 139..166 'foo(&(...y)| x)': i32 | 607 | 139..166 'foo(&(...y)| x)': i32 |
606 | 143..152 '&(1, "a")': &(i32, &str) | 608 | 143..152 '&(1, "a")': &(i32, &str) |
607 | 144..152 '(1, "a")': (i32, &str) | 609 | 144..152 '(1, "a")': (i32, &str) |
608 | 145..146 '1': i32 | 610 | 145..146 '1': i32 |
609 | 148..151 '"a"': &str | 611 | 148..151 '"a"': &str |
610 | 154..165 '|&(x, y)| x': |&(i32, &str)| -> i32 | 612 | 154..165 '|&(x, y)| x': |&(i32, &str)| -> i32 |
611 | 155..162 '&(x, y)': &(i32, &str) | 613 | 155..162 '&(x, y)': &(i32, &str) |
612 | 156..162 '(x, y)': (i32, &str) | 614 | 156..162 '(x, y)': (i32, &str) |
613 | 157..158 'x': i32 | 615 | 157..158 'x': i32 |
614 | 160..161 'y': &str | 616 | 160..161 'y': &str |
615 | 164..165 'x': i32 | 617 | 164..165 'x': i32 |
616 | 203..206 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32 | 618 | 203..206 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32 |
617 | 203..229 'foo(&(...y)| x)': &i32 | 619 | 203..229 'foo(&(...y)| x)': &i32 |
618 | 207..216 '&(1, "a")': &(i32, &str) | 620 | 207..216 '&(1, "a")': &(i32, &str) |
619 | 208..216 '(1, "a")': (i32, &str) | 621 | 208..216 '(1, "a")': (i32, &str) |
620 | 209..210 '1': i32 | 622 | 209..210 '1': i32 |
621 | 212..215 '"a"': &str | 623 | 212..215 '"a"': &str |
622 | 218..228 '|(x, y)| x': |&(i32, &str)| -> &i32 | 624 | 218..228 '|(x, y)| x': |&(i32, &str)| -> &i32 |
623 | 219..225 '(x, y)': (i32, &str) | 625 | 219..225 '(x, y)': (i32, &str) |
624 | 220..221 'x': &i32 | 626 | 220..221 'x': &i32 |
625 | 223..224 'y': &&str | 627 | 223..224 'y': &&str |
626 | 227..228 'x': &i32 | 628 | 227..228 'x': &i32 |
627 | "### | 629 | "#]], |
628 | ); | 630 | ); |
629 | } | 631 | } |
630 | 632 | ||
631 | #[test] | 633 | #[test] |
632 | fn slice_tail_pattern() { | 634 | fn slice_tail_pattern() { |
633 | assert_snapshot!( | 635 | check_infer( |
634 | infer(r#" | 636 | r#" |
635 | fn foo(params: &[i32]) { | 637 | fn foo(params: &[i32]) { |
636 | match params { | 638 | match params { |
637 | [head, tail @ ..] => { | 639 | [head, tail @ ..] => { |
640 | } | ||
641 | } | ||
638 | } | 642 | } |
639 | } | 643 | "#, |
640 | } | 644 | expect![[r#" |
641 | "#), | 645 | 7..13 'params': &[i32] |
642 | @r###" | 646 | 23..92 '{ ... } }': () |
643 | 7..13 'params': &[i32] | 647 | 29..90 'match ... }': () |
644 | 23..92 '{ ... } }': () | 648 | 35..41 'params': &[i32] |
645 | 29..90 'match ... }': () | 649 | 52..69 '[head,... @ ..]': [i32] |
646 | 35..41 'params': &[i32] | 650 | 53..57 'head': &i32 |
647 | 52..69 '[head,... @ ..]': [i32] | 651 | 59..68 'tail @ ..': &[i32] |
648 | 53..57 'head': &i32 | 652 | 66..68 '..': [i32] |
649 | 59..68 'tail @ ..': &[i32] | 653 | 73..84 '{ }': () |
650 | 66..68 '..': [i32] | 654 | "#]], |
651 | 73..84 '{ }': () | ||
652 | "### | ||
653 | ); | 655 | ); |
654 | } | 656 | } |