diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 39 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/backwards.txt (renamed from crates/ra_hir/src/ty/tests/data/0006_backwards.txt) | 30 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/basics.txt (renamed from crates/ra_hir/src/ty/tests/data/0001_basics.txt) | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/boolean_op.txt (renamed from crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt) | 48 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/let.txt (renamed from crates/ra_hir/src/ty/tests/data/0002_let.txt) | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/paths.txt (renamed from crates/ra_hir/src/ty/tests/data/0003_paths.txt) | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt (renamed from crates/ra_hir/src/ty/tests/data/0005_refs.txt) | 32 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/self.txt (renamed from crates/ra_hir/src/ty/tests/data/0007_self.txt) | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/struct.txt (renamed from crates/ra_hir/src/ty/tests/data/0004_struct.txt) | 22 |
9 files changed, 109 insertions, 92 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 25a354947..83aedaa00 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -5,7 +5,7 @@ use std::fs; | |||
5 | 5 | ||
6 | use salsa::Database; | 6 | use salsa::Database; |
7 | 7 | ||
8 | use ra_db::{SyntaxDatabase}; | 8 | use ra_db::SyntaxDatabase; |
9 | use ra_syntax::ast::{self, AstNode}; | 9 | use ra_syntax::ast::{self, AstNode}; |
10 | use test_utils::{project_dir, assert_eq_text, read_text}; | 10 | use test_utils::{project_dir, assert_eq_text, read_text}; |
11 | 11 | ||
@@ -34,7 +34,7 @@ fn test(a: u32, b: isize, c: !, d: &str) { | |||
34 | "test"; | 34 | "test"; |
35 | 1.0f32; | 35 | 1.0f32; |
36 | }"#, | 36 | }"#, |
37 | "0001_basics.txt", | 37 | "basics.txt", |
38 | ); | 38 | ); |
39 | } | 39 | } |
40 | 40 | ||
@@ -48,7 +48,7 @@ fn test() { | |||
48 | let c = b; | 48 | let c = b; |
49 | } | 49 | } |
50 | }"#, | 50 | }"#, |
51 | "0002_let.txt", | 51 | "let.txt", |
52 | ); | 52 | ); |
53 | } | 53 | } |
54 | 54 | ||
@@ -67,7 +67,7 @@ fn test() { | |||
67 | b::c(); | 67 | b::c(); |
68 | } | 68 | } |
69 | }"#, | 69 | }"#, |
70 | "0003_paths.txt", | 70 | "paths.txt", |
71 | ); | 71 | ); |
72 | } | 72 | } |
73 | 73 | ||
@@ -90,7 +90,7 @@ fn test() { | |||
90 | a.c; | 90 | a.c; |
91 | } | 91 | } |
92 | "#, | 92 | "#, |
93 | "0004_struct.txt", | 93 | "struct.txt", |
94 | ); | 94 | ); |
95 | } | 95 | } |
96 | 96 | ||
@@ -112,7 +112,7 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { | |||
112 | *d; | 112 | *d; |
113 | } | 113 | } |
114 | "#, | 114 | "#, |
115 | "0005_refs.txt", | 115 | "refs_and_ptrs.txt", |
116 | ); | 116 | ); |
117 | } | 117 | } |
118 | 118 | ||
@@ -133,7 +133,7 @@ fn test() -> &mut &f64 { | |||
133 | &mut &c | 133 | &mut &c |
134 | } | 134 | } |
135 | "#, | 135 | "#, |
136 | "0006_backwards.txt", | 136 | "backwards.txt", |
137 | ); | 137 | ); |
138 | } | 138 | } |
139 | 139 | ||
@@ -152,7 +152,7 @@ impl S { | |||
152 | } | 152 | } |
153 | } | 153 | } |
154 | "#, | 154 | "#, |
155 | "0007_self.txt", | 155 | "self.txt", |
156 | ); | 156 | ); |
157 | } | 157 | } |
158 | 158 | ||
@@ -176,7 +176,7 @@ fn test() { | |||
176 | 10 < 3 | 176 | 10 < 3 |
177 | } | 177 | } |
178 | "#, | 178 | "#, |
179 | "0008_boolean_op.txt", | 179 | "boolean_op.txt", |
180 | ); | 180 | ); |
181 | } | 181 | } |
182 | 182 | ||
@@ -193,7 +193,25 @@ fn infer(content: &str) -> String { | |||
193 | .unwrap() | 193 | .unwrap() |
194 | .unwrap(); | 194 | .unwrap(); |
195 | let inference_result = func.infer(&db).unwrap(); | 195 | let inference_result = func.infer(&db).unwrap(); |
196 | for (syntax_ptr, ty) in &inference_result.type_of { | 196 | let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); |
197 | let mut types = Vec::new(); | ||
198 | for (pat, ty) in inference_result.type_of_pat.iter() { | ||
199 | let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { | ||
200 | Some(sp) => sp, | ||
201 | None => continue, | ||
202 | }; | ||
203 | types.push((syntax_ptr, ty)); | ||
204 | } | ||
205 | for (expr, ty) in inference_result.type_of_expr.iter() { | ||
206 | let syntax_ptr = match body_syntax_mapping.expr_syntax(expr) { | ||
207 | Some(sp) => sp, | ||
208 | None => continue, | ||
209 | }; | ||
210 | types.push((syntax_ptr, ty)); | ||
211 | } | ||
212 | // sort ranges for consistency | ||
213 | types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); | ||
214 | for (syntax_ptr, ty) in &types { | ||
197 | let node = syntax_ptr.resolve(&source_file); | 215 | let node = syntax_ptr.resolve(&source_file); |
198 | write!( | 216 | write!( |
199 | acc, | 217 | acc, |
@@ -246,7 +264,6 @@ fn test_data_dir() -> PathBuf { | |||
246 | } | 264 | } |
247 | 265 | ||
248 | #[test] | 266 | #[test] |
249 | #[should_panic] // TODO this should work once hir::Expr is used | ||
250 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | 267 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { |
251 | let (mut db, pos) = MockDatabase::with_position( | 268 | let (mut db, pos) = MockDatabase::with_position( |
252 | " | 269 | " |
diff --git a/crates/ra_hir/src/ty/tests/data/0006_backwards.txt b/crates/ra_hir/src/ty/tests/data/backwards.txt index 120069401..b6807fb2a 100644 --- a/crates/ra_hir/src/ty/tests/data/0006_backwards.txt +++ b/crates/ra_hir/src/ty/tests/data/backwards.txt | |||
@@ -1,20 +1,20 @@ | |||
1 | [22; 24) '{}': () | ||
2 | [14; 15) 'x': u32 | 1 | [14; 15) 'x': u32 |
3 | [142; 158) 'unknow...nction': [unknown] | 2 | [22; 24) '{}': () |
4 | [126; 127) 'a': u32 | ||
5 | [198; 216) 'unknow...tion()': f64 | ||
6 | [228; 229) 'c': f64 | ||
7 | [198; 214) 'unknow...nction': [unknown] | ||
8 | [166; 184) 'S { i3...d: b }': S | ||
9 | [222; 229) '&mut &c': &mut &f64 | ||
10 | [194; 195) 'c': f64 | ||
11 | [92; 110) 'unknow...tion()': u32 | ||
12 | [142; 160) 'unknow...tion()': i32 | ||
13 | [92; 108) 'unknow...nction': [unknown] | ||
14 | [116; 128) 'takes_u32(a)': () | ||
15 | [78; 231) '{ ...t &c }': &mut &f64 | 3 | [78; 231) '{ ...t &c }': &mut &f64 |
16 | [227; 229) '&c': &f64 | ||
17 | [88; 89) 'a': u32 | 4 | [88; 89) 'a': u32 |
18 | [181; 182) 'b': i32 | 5 | [92; 108) 'unknow...nction': [unknown] |
6 | [92; 110) 'unknow...tion()': u32 | ||
19 | [116; 125) 'takes_u32': fn(u32,) -> () | 7 | [116; 125) 'takes_u32': fn(u32,) -> () |
8 | [116; 128) 'takes_u32(a)': () | ||
9 | [126; 127) 'a': u32 | ||
20 | [138; 139) 'b': i32 | 10 | [138; 139) 'b': i32 |
11 | [142; 158) 'unknow...nction': [unknown] | ||
12 | [142; 160) 'unknow...tion()': i32 | ||
13 | [166; 184) 'S { i3...d: b }': S | ||
14 | [181; 182) 'b': i32 | ||
15 | [194; 195) 'c': f64 | ||
16 | [198; 214) 'unknow...nction': [unknown] | ||
17 | [198; 216) 'unknow...tion()': f64 | ||
18 | [222; 229) '&mut &c': &mut &f64 | ||
19 | [227; 229) '&c': &f64 | ||
20 | [228; 229) 'c': f64 | ||
diff --git a/crates/ra_hir/src/ty/tests/data/0001_basics.txt b/crates/ra_hir/src/ty/tests/data/basics.txt index 212e92e00..8ea244ba8 100644 --- a/crates/ra_hir/src/ty/tests/data/0001_basics.txt +++ b/crates/ra_hir/src/ty/tests/data/basics.txt | |||
@@ -1,13 +1,13 @@ | |||
1 | [9; 10) 'a': u32 | ||
2 | [17; 18) 'b': isize | ||
3 | [27; 28) 'c': ! | ||
1 | [33; 34) 'd': &[unknown] | 4 | [33; 34) 'd': &[unknown] |
2 | [88; 94) '1isize': [unknown] | 5 | [42; 121) '{ ...f32; }': () |
3 | [48; 49) 'a': u32 | 6 | [48; 49) 'a': u32 |
4 | [55; 56) 'b': isize | 7 | [55; 56) 'b': isize |
5 | [112; 118) '1.0f32': [unknown] | ||
6 | [76; 82) '1usize': [unknown] | ||
7 | [9; 10) 'a': u32 | ||
8 | [27; 28) 'c': ! | ||
9 | [62; 63) 'c': ! | 8 | [62; 63) 'c': ! |
10 | [17; 18) 'b': isize | ||
11 | [100; 106) '"test"': [unknown] | ||
12 | [42; 121) '{ ...f32; }': () | ||
13 | [69; 70) 'd': &[unknown] | 9 | [69; 70) 'd': &[unknown] |
10 | [76; 82) '1usize': [unknown] | ||
11 | [88; 94) '1isize': [unknown] | ||
12 | [100; 106) '"test"': [unknown] | ||
13 | [112; 118) '1.0f32': [unknown] | ||
diff --git a/crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt b/crates/ra_hir/src/ty/tests/data/boolean_op.txt index ca01ad159..cce8d68fb 100644 --- a/crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt +++ b/crates/ra_hir/src/ty/tests/data/boolean_op.txt | |||
@@ -1,31 +1,31 @@ | |||
1 | [28; 32) '0i32': i32 | ||
2 | [22; 34) '{ 0i32 }': i32 | ||
3 | [6; 7) 'x': [unknown] | 1 | [6; 7) 'x': [unknown] |
4 | [127; 134) 'CONST_1': [unknown] | 2 | [22; 34) '{ 0i32 }': i32 |
5 | [201; 205) '3i32': bool | 3 | [28; 32) '0i32': i32 |
6 | [76; 77) 'y': bool | 4 | [46; 237) '{ ... < 3 }': bool |
7 | [65; 66) 'b': bool | 5 | [56; 57) 'x': bool |
6 | [60; 61) 'a': bool | ||
8 | [60; 66) 'a && b': bool | 7 | [60; 66) 'a && b': bool |
8 | [65; 66) 'b': bool | ||
9 | [76; 77) 'y': bool | ||
10 | [80; 84) 'true': bool | ||
11 | [80; 93) 'true || false': bool | ||
12 | [88; 93) 'false': bool | ||
13 | [103; 104) 'z': bool | ||
14 | [107; 108) 'x': bool | ||
15 | [107; 113) 'x == y': bool | ||
16 | [112; 113) 'y': bool | ||
17 | [123; 124) 'h': bool | ||
18 | [127; 134) 'CONST_1': [unknown] | ||
9 | [127; 145) 'CONST_...ONST_2': bool | 19 | [127; 145) 'CONST_...ONST_2': bool |
20 | [138; 145) 'CONST_2': [unknown] | ||
21 | [155; 156) 'c': [unknown] | ||
22 | [159; 172) 'f(z || y) + 5': [unknown] | ||
10 | [182; 183) 'd': [unknown] | 23 | [182; 183) 'd': [unknown] |
11 | [229; 231) '10': [unknown] | ||
12 | [209; 222) '"hello world"': bool | ||
13 | [229; 235) '10 < 3': bool | ||
14 | [186; 187) 'b': [unknown] | 24 | [186; 187) 'b': [unknown] |
15 | [159; 172) 'f(z || y) + 5': [unknown] | 25 | [197; 198) 'e': bool |
16 | [56; 57) 'x': bool | 26 | [201; 205) '3i32': bool |
17 | [112; 113) 'y': bool | ||
18 | [201; 222) '3i32 &...world"': bool | 27 | [201; 222) '3i32 &...world"': bool |
28 | [209; 222) '"hello world"': bool | ||
29 | [229; 231) '10': [unknown] | ||
30 | [229; 235) '10 < 3': bool | ||
19 | [234; 235) '3': [unknown] | 31 | [234; 235) '3': [unknown] |
20 | [138; 145) 'CONST_2': [unknown] | ||
21 | [80; 93) 'true || false': bool | ||
22 | [46; 237) '{ ... < 3 }': bool | ||
23 | [197; 198) 'e': bool | ||
24 | [107; 113) 'x == y': bool | ||
25 | [88; 93) 'false': bool | ||
26 | [80; 84) 'true': bool | ||
27 | [123; 124) 'h': bool | ||
28 | [155; 156) 'c': [unknown] | ||
29 | [103; 104) 'z': bool | ||
30 | [60; 61) 'a': bool | ||
31 | [107; 108) 'x': bool | ||
diff --git a/crates/ra_hir/src/ty/tests/data/0002_let.txt b/crates/ra_hir/src/ty/tests/data/let.txt index 916ca25a1..30f4a2cf5 100644 --- a/crates/ra_hir/src/ty/tests/data/0002_let.txt +++ b/crates/ra_hir/src/ty/tests/data/let.txt | |||
@@ -1,7 +1,7 @@ | |||
1 | [21; 22) 'a': [unknown] | ||
2 | [52; 53) '1': usize | ||
3 | [11; 71) '{ ...= b; }': () | 1 | [11; 71) '{ ...= b; }': () |
4 | [63; 64) 'c': usize | 2 | [21; 22) 'a': [unknown] |
5 | [25; 31) '1isize': [unknown] | 3 | [25; 31) '1isize': [unknown] |
6 | [41; 42) 'b': usize | 4 | [41; 42) 'b': usize |
5 | [52; 53) '1': usize | ||
6 | [63; 64) 'c': usize | ||
7 | [67; 68) 'b': usize | 7 | [67; 68) 'b': usize |
diff --git a/crates/ra_hir/src/ty/tests/data/0003_paths.txt b/crates/ra_hir/src/ty/tests/data/paths.txt index 2a12d264f..b22f4d4a5 100644 --- a/crates/ra_hir/src/ty/tests/data/0003_paths.txt +++ b/crates/ra_hir/src/ty/tests/data/paths.txt | |||
@@ -1,9 +1,9 @@ | |||
1 | [15; 20) '{ 1 }': u32 | 1 | [15; 20) '{ 1 }': u32 |
2 | [17; 18) '1': u32 | 2 | [17; 18) '1': u32 |
3 | [50; 51) '1': u32 | ||
4 | [48; 53) '{ 1 }': u32 | 3 | [48; 53) '{ 1 }': u32 |
5 | [82; 88) 'b::c()': u32 | 4 | [50; 51) '1': u32 |
6 | [67; 91) '{ ...c(); }': () | 5 | [67; 91) '{ ...c(); }': () |
7 | [73; 74) 'a': fn() -> u32 | 6 | [73; 74) 'a': fn() -> u32 |
8 | [73; 76) 'a()': u32 | 7 | [73; 76) 'a()': u32 |
9 | [82; 86) 'b::c': fn() -> u32 | 8 | [82; 86) 'b::c': fn() -> u32 |
9 | [82; 88) 'b::c()': u32 | ||
diff --git a/crates/ra_hir/src/ty/tests/data/0005_refs.txt b/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt index 296e955c1..afab343ea 100644 --- a/crates/ra_hir/src/ty/tests/data/0005_refs.txt +++ b/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt | |||
@@ -1,23 +1,23 @@ | |||
1 | [115; 117) '&b': &&mut u32 | 1 | [9; 10) 'a': &u32 |
2 | [88; 94) '&mut a': &mut &u32 | 2 | [18; 19) 'b': &mut u32 |
3 | [146; 147) 'd': *mut u32 | 3 | [31; 32) 'c': *const u32 |
4 | [145; 147) '*d': u32 | ||
5 | [65; 66) 'a': &u32 | ||
6 | [46; 47) 'd': *mut u32 | 4 | [46; 47) 'd': *mut u32 |
7 | [59; 150) '{ ... *d; }': () | 5 | [59; 150) '{ ... *d; }': () |
8 | [116; 117) 'b': &mut u32 | 6 | [65; 66) 'a': &u32 |
9 | [131; 132) 'c': *const u32 | ||
10 | [130; 132) '*c': u32 | ||
11 | [72; 74) '*a': u32 | 7 | [72; 74) '*a': u32 |
12 | [107; 109) '*b': u32 | 8 | [73; 74) 'a': &u32 |
13 | [108; 109) 'b': &mut u32 | 9 | [80; 82) '&a': &&u32 |
14 | [9; 10) 'a': &u32 | 10 | [81; 82) 'a': &u32 |
15 | [18; 19) 'b': &mut u32 | 11 | [88; 94) '&mut a': &mut &u32 |
16 | [93; 94) 'a': &u32 | 12 | [93; 94) 'a': &u32 |
17 | [100; 101) 'b': &mut u32 | 13 | [100; 101) 'b': &mut u32 |
18 | [81; 82) 'a': &u32 | 14 | [107; 109) '*b': u32 |
19 | [80; 82) '&a': &&u32 | 15 | [108; 109) 'b': &mut u32 |
20 | [73; 74) 'a': &u32 | 16 | [115; 117) '&b': &&mut u32 |
17 | [116; 117) 'b': &mut u32 | ||
21 | [123; 124) 'c': *const u32 | 18 | [123; 124) 'c': *const u32 |
22 | [31; 32) 'c': *const u32 | 19 | [130; 132) '*c': u32 |
20 | [131; 132) 'c': *const u32 | ||
23 | [138; 139) 'd': *mut u32 | 21 | [138; 139) 'd': *mut u32 |
22 | [145; 147) '*d': u32 | ||
23 | [146; 147) 'd': *mut u32 | ||
diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/self.txt index db4ba17d0..c38029f97 100644 --- a/crates/ra_hir/src/ty/tests/data/0007_self.txt +++ b/crates/ra_hir/src/ty/tests/data/self.txt | |||
@@ -1,6 +1,6 @@ | |||
1 | [50; 54) 'self': &S | ||
2 | [34; 38) 'self': &S | 1 | [34; 38) 'self': &S |
3 | [40; 61) '{ ... }': () | 2 | [40; 61) '{ ... }': () |
3 | [50; 54) 'self': &S | ||
4 | [75; 79) 'self': &S | ||
4 | [88; 109) '{ ... }': () | 5 | [88; 109) '{ ... }': () |
5 | [98; 102) 'self': &S | 6 | [98; 102) 'self': &S |
6 | [75; 79) 'self': &S | ||
diff --git a/crates/ra_hir/src/ty/tests/data/0004_struct.txt b/crates/ra_hir/src/ty/tests/data/struct.txt index b4af18b87..7b324c82f 100644 --- a/crates/ra_hir/src/ty/tests/data/0004_struct.txt +++ b/crates/ra_hir/src/ty/tests/data/struct.txt | |||
@@ -1,16 +1,16 @@ | |||
1 | [86; 90) 'C(1)': [unknown] | 1 | [72; 154) '{ ...a.c; }': () |
2 | [121; 122) 'B': B | 2 | [82; 83) 'c': [unknown] |
3 | [86; 87) 'C': [unknown] | 3 | [86; 87) 'C': [unknown] |
4 | [129; 130) '1': [unknown] | 4 | [86; 90) 'C(1)': [unknown] |
5 | [88; 89) '1': [unknown] | ||
6 | [96; 97) 'B': [unknown] | ||
5 | [107; 108) 'a': A | 7 | [107; 108) 'a': A |
8 | [114; 133) 'A { b:...C(1) }': A | ||
9 | [121; 122) 'B': B | ||
6 | [127; 128) 'C': [unknown] | 10 | [127; 128) 'C': [unknown] |
11 | [127; 131) 'C(1)': C | ||
12 | [129; 130) '1': [unknown] | ||
13 | [139; 140) 'a': A | ||
7 | [139; 142) 'a.b': B | 14 | [139; 142) 'a.b': B |
8 | [114; 133) 'A { b:...C(1) }': A | ||
9 | [148; 151) 'a.c': C | ||
10 | [148; 149) 'a': A | 15 | [148; 149) 'a': A |
11 | [139; 140) 'a': A | 16 | [148; 151) 'a.c': C |
12 | [72; 154) '{ ...a.c; }': () | ||
13 | [96; 97) 'B': [unknown] | ||
14 | [88; 89) '1': [unknown] | ||
15 | [82; 83) 'c': [unknown] | ||
16 | [127; 131) 'C(1)': C | ||