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