diff options
author | Aleksey Kladov <[email protected]> | 2019-12-05 20:17:17 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-05 20:17:17 +0000 |
commit | b84ce79f911014dfed6bc9d31d6699bc123d3561 (patch) | |
tree | b0978346224588b9c3186cc6bc895d9b25b2bb51 /crates/ra_hir_ty/src | |
parent | 6e10a9f57815ad865a570816436adfdf0de1cdf0 (diff) |
Simplify test
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index c520bb375..9f373a8f4 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -11,8 +11,8 @@ use std::fmt::Write; | |||
11 | use std::sync::Arc; | 11 | use std::sync::Arc; |
12 | 12 | ||
13 | use hir_def::{ | 13 | use hir_def::{ |
14 | body::BodySourceMap, db::DefDatabase, nameres::CrateDefMap, AssocItemId, DefWithBodyId, | 14 | body::BodySourceMap, child_from_source::ChildFromSource, db::DefDatabase, nameres::CrateDefMap, |
15 | LocalModuleId, Lookup, ModuleDefId, | 15 | AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, |
16 | }; | 16 | }; |
17 | use hir_expand::InFile; | 17 | use hir_expand::InFile; |
18 | use insta::assert_snapshot; | 18 | use insta::assert_snapshot; |
@@ -31,18 +31,15 @@ use crate::{db::HirDatabase, display::HirDisplay, test_db::TestDB, InferenceResu | |||
31 | fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { | 31 | fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { |
32 | let file = db.parse(pos.file_id).ok().unwrap(); | 32 | let file = db.parse(pos.file_id).ok().unwrap(); |
33 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 33 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |
34 | 34 | let fn_def = expr.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); | |
35 | let module = db.module_for_file(pos.file_id); | 35 | let module = db.module_for_file(pos.file_id); |
36 | let crate_def_map = db.crate_def_map(module.krate); | 36 | let func = module.child_from_source(db, InFile::new(pos.file_id.into(), fn_def)).unwrap(); |
37 | for decl in crate_def_map[module.local_id].scope.declarations() { | 37 | |
38 | if let ModuleDefId::FunctionId(func) = decl { | 38 | let (_body, source_map) = db.body_with_source_map(func.into()); |
39 | let (_body, source_map) = db.body_with_source_map(func.into()); | 39 | if let Some(expr_id) = source_map.node_expr(InFile::new(pos.file_id.into(), &expr)) { |
40 | if let Some(expr_id) = source_map.node_expr(InFile::new(pos.file_id.into(), &expr)) { | 40 | let infer = db.infer(func.into()); |
41 | let infer = db.infer(func.into()); | 41 | let ty = &infer[expr_id]; |
42 | let ty = &infer[expr_id]; | 42 | return ty.display(db).to_string(); |
43 | return ty.display(db).to_string(); | ||
44 | } | ||
45 | } | ||
46 | } | 43 | } |
47 | panic!("Can't find expression") | 44 | panic!("Can't find expression") |
48 | } | 45 | } |