diff options
author | Florian Diebold <[email protected]> | 2019-01-06 15:47:59 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-06 23:05:19 +0000 |
commit | 6210e82041849bad6129331b9e45ac0bae6fe569 (patch) | |
tree | 43656452729519e45f4aa036372526b2934a230c /crates/ra_hir/src/ty/tests.rs | |
parent | 3c945ceb5e0dc287139de0589cc9a4b285911f17 (diff) |
Use HIR Expr for type inference
Now we can reuse the type inference inside a function when typing whitespace
etc. :)
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 25a354947..e46f309ae 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -4,8 +4,9 @@ use std::path::{PathBuf, Path}; | |||
4 | use std::fs; | 4 | use std::fs; |
5 | 5 | ||
6 | use salsa::Database; | 6 | use salsa::Database; |
7 | use rustc_hash::FxHashMap; | ||
7 | 8 | ||
8 | use ra_db::{SyntaxDatabase}; | 9 | use ra_db::SyntaxDatabase; |
9 | use ra_syntax::ast::{self, AstNode}; | 10 | use ra_syntax::ast::{self, AstNode}; |
10 | use test_utils::{project_dir, assert_eq_text, read_text}; | 11 | use test_utils::{project_dir, assert_eq_text, read_text}; |
11 | 12 | ||
@@ -193,7 +194,25 @@ fn infer(content: &str) -> String { | |||
193 | .unwrap() | 194 | .unwrap() |
194 | .unwrap(); | 195 | .unwrap(); |
195 | let inference_result = func.infer(&db).unwrap(); | 196 | let inference_result = func.infer(&db).unwrap(); |
196 | for (syntax_ptr, ty) in &inference_result.type_of { | 197 | let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); |
198 | let mut types = FxHashMap::default(); | ||
199 | for (pat, ty) in &inference_result.type_of_pat { | ||
200 | let syntax_ptr = if let Some(sp) = body_syntax_mapping.pat_syntax(*pat) { | ||
201 | sp | ||
202 | } else { | ||
203 | continue; | ||
204 | }; | ||
205 | types.insert(syntax_ptr, ty); | ||
206 | } | ||
207 | for (expr, ty) in &inference_result.type_of_expr { | ||
208 | let syntax_ptr = if let Some(sp) = body_syntax_mapping.expr_syntax(*expr) { | ||
209 | sp | ||
210 | } else { | ||
211 | continue; | ||
212 | }; | ||
213 | types.insert(syntax_ptr, ty); | ||
214 | } | ||
215 | for (syntax_ptr, ty) in &types { | ||
197 | let node = syntax_ptr.resolve(&source_file); | 216 | let node = syntax_ptr.resolve(&source_file); |
198 | write!( | 217 | write!( |
199 | acc, | 218 | acc, |
@@ -246,7 +265,6 @@ fn test_data_dir() -> PathBuf { | |||
246 | } | 265 | } |
247 | 266 | ||
248 | #[test] | 267 | #[test] |
249 | #[should_panic] // TODO this should work once hir::Expr is used | ||
250 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | 268 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { |
251 | let (mut db, pos) = MockDatabase::with_position( | 269 | let (mut db, pos) = MockDatabase::with_position( |
252 | " | 270 | " |