aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-16 15:11:19 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-16 15:11:19 +0000
commit454cc313589fb17de92d6f3dbf576a5ea5f4adf2 (patch)
treee67129e4e514e140463d8f0f7bd7556793cac484 /crates/ra_hir/src/ty
parentd75a0368f5048243d6561e42e77835f6f574b321 (diff)
parent0aedd4fb2f28ec24902d26c7d8a24d6146263d2f (diff)
Merge #524
524: Implement array inference r=flodiebold a=h-michael related #394 Co-authored-by: Hirokazu Hata <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/tests.rs26
-rw-r--r--crates/ra_hir/src/ty/tests/data/array.txt52
2 files changed, 78 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 5d7bc25cc..affd63a85 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -334,6 +334,32 @@ fn test(x: &str, y: isize) {
334 ); 334 );
335} 335}
336 336
337#[test]
338fn infer_array() {
339 check_inference(
340 r#"
341fn test(x: &str, y: isize) {
342 let a = [x];
343 let b = [a, a];
344 let c = [b, b];
345
346 let d = [y, 1, 2, 3];
347 let d = [1, y, 2, 3];
348 let e = [y];
349 let f = [d, d];
350 let g = [e, e];
351
352 let h = [1, 2];
353 let i = ["a", "b"];
354
355 let b = [a, ["b"]];
356 let x: [u8; 0] = [];
357}
358"#,
359 "array.txt",
360 );
361}
362
337fn infer(content: &str) -> String { 363fn infer(content: &str) -> String {
338 let (db, _, file_id) = MockDatabase::with_single_file(content); 364 let (db, _, file_id) = MockDatabase::with_single_file(content);
339 let source_file = db.source_file(file_id); 365 let source_file = db.source_file(file_id);
diff --git a/crates/ra_hir/src/ty/tests/data/array.txt b/crates/ra_hir/src/ty/tests/data/array.txt
new file mode 100644
index 000000000..acdf74ba4
--- /dev/null
+++ b/crates/ra_hir/src/ty/tests/data/array.txt
@@ -0,0 +1,52 @@
1[9; 10) 'x': &str
2[18; 19) 'y': isize
3[28; 293) '{ ... []; }': ()
4[38; 39) 'a': [&str]
5[42; 45) '[x]': [&str]
6[43; 44) 'x': &str
7[55; 56) 'b': [[&str]]
8[59; 65) '[a, a]': [[&str]]
9[60; 61) 'a': [&str]
10[63; 64) 'a': [&str]
11[75; 76) 'c': [[[&str]]]
12[79; 85) '[b, b]': [[[&str]]]
13[80; 81) 'b': [[&str]]
14[83; 84) 'b': [[&str]]
15[96; 97) 'd': [isize]
16[100; 112) '[y, 1, 2, 3]': [isize]
17[101; 102) 'y': isize
18[104; 105) '1': isize
19[107; 108) '2': isize
20[110; 111) '3': isize
21[122; 123) 'd': [isize]
22[126; 138) '[1, y, 2, 3]': [isize]
23[127; 128) '1': isize
24[130; 131) 'y': isize
25[133; 134) '2': isize
26[136; 137) '3': isize
27[148; 149) 'e': [isize]
28[152; 155) '[y]': [isize]
29[153; 154) 'y': isize
30[165; 166) 'f': [[isize]]
31[169; 175) '[d, d]': [[isize]]
32[170; 171) 'd': [isize]
33[173; 174) 'd': [isize]
34[185; 186) 'g': [[isize]]
35[189; 195) '[e, e]': [[isize]]
36[190; 191) 'e': [isize]
37[193; 194) 'e': [isize]
38[206; 207) 'h': [i32]
39[210; 216) '[1, 2]': [i32]
40[211; 212) '1': i32
41[214; 215) '2': i32
42[226; 227) 'i': [&str]
43[230; 240) '["a", "b"]': [&str]
44[231; 234) '"a"': &str
45[236; 239) '"b"': &str
46[251; 252) 'b': [[&str]]
47[255; 265) '[a, ["b"]]': [[&str]]
48[256; 257) 'a': [&str]
49[259; 264) '["b"]': [&str]
50[260; 263) '"b"': &str
51[275; 276) 'x': [u8]
52[288; 290) '[]': [u8]