aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-06 00:24:11 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-06 00:24:11 +0100
commit990e74ba7c77485f914434ac6f09a40d1364634d (patch)
tree9e979e9ec084d717db9d4326df3a970db8d28947 /crates/ra_hir/src/ty
parent9d39b7bc42e6186b0fd6e1cec746d58c950f780e (diff)
parent2caa690ef6feba3f78354e715deea37983b149ac (diff)
Merge #1117
1117: [WIP] Tuple struct index inference r=matklad a=robojumper The first commit adds a helper struct `ast::FieldKind` to facilitate inference. The second commit adds a slightly modified test from #1109 while mentioning that there is a problem with how we're handling tuple indexing / floats. cc #1109 Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/tests.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 0b7c841df..f0164f7ea 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2242,6 +2242,65 @@ static B: u64 = { let x = 1; x };
2242 ); 2242 );
2243} 2243}
2244 2244
2245#[test]
2246fn tuple_struct_fields() {
2247 assert_snapshot_matches!(
2248 infer(r#"
2249struct S(i32, u64);
2250fn test() -> u64 {
2251 let a = S(4, 6);
2252 let b = a.0;
2253 a.1
2254}
2255"#),
2256 @r###"
2257[38; 87) '{ ... a.1 }': u64
2258[48; 49) 'a': S
2259[52; 53) 'S': S(i32, u64) -> S
2260[52; 59) 'S(4, 6)': S
2261[54; 55) '4': i32
2262[57; 58) '6': u64
2263[69; 70) 'b': i32
2264[73; 74) 'a': S
2265[73; 76) 'a.0': i32
2266[82; 83) 'a': S
2267[82; 85) 'a.1': u64"###
2268 );
2269}
2270
2271#[test]
2272fn tuple_struct_with_fn() {
2273 assert_snapshot_matches!(
2274 infer(r#"
2275struct S(fn(u32) -> u64);
2276fn test() -> u64 {
2277 let a = S(|i| 2*i);
2278 let b = a.0(4);
2279 a.0(2)
2280}
2281"#),
2282 @r###"
2283[44; 102) '{ ...0(2) }': u64
2284[54; 55) 'a': S
2285[58; 59) 'S': S(fn(u32) -> u64) -> S
2286[58; 68) 'S(|i| 2*i)': S
2287[60; 67) '|i| 2*i': fn(u32) -> u64
2288[61; 62) 'i': i32
2289[64; 65) '2': i32
2290[64; 67) '2*i': i32
2291[66; 67) 'i': i32
2292[78; 79) 'b': u64
2293[82; 83) 'a': S
2294[82; 85) 'a.0': fn(u32) -> u64
2295[82; 88) 'a.0(4)': u64
2296[86; 87) '4': u32
2297[94; 95) 'a': S
2298[94; 97) 'a.0': fn(u32) -> u64
2299[94; 100) 'a.0(2)': u64
2300[98; 99) '2': u32"###
2301 );
2302}
2303
2245fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 2304fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
2246 let func = source_binder::function_from_position(db, pos).unwrap(); 2305 let func = source_binder::function_from_position(db, pos).unwrap();
2247 let body_source_map = func.body_source_map(db); 2306 let body_source_map = func.body_source_map(db);