diff options
author | Aleksey Kladov <[email protected]> | 2019-01-15 15:13:11 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-15 15:13:49 +0000 |
commit | 11f3c8afb23d67acde8cc7642aea3a2ca06a2361 (patch) | |
tree | 324f517c3e8cc42be6f3e8349c55683695ea4558 /crates/ra_hir | |
parent | a36b2cf377a90cf13bb097e57878b8384d30c53a (diff) |
remove Cancelable from source binders
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 21 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 62 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 8 |
9 files changed, 56 insertions, 76 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 91b235594..5db53a34f 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -109,7 +109,7 @@ impl Module { | |||
109 | } | 109 | } |
110 | 110 | ||
111 | /// Finds a child module with the specified name. | 111 | /// Finds a child module with the specified name. |
112 | pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { | 112 | pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { |
113 | self.child_impl(db, name) | 113 | self.child_impl(db, name) |
114 | } | 114 | } |
115 | 115 | ||
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 2ec3ab469..67808d282 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -18,7 +18,7 @@ impl Module { | |||
18 | db: &impl HirDatabase, | 18 | db: &impl HirDatabase, |
19 | source_root_id: SourceRootId, | 19 | source_root_id: SourceRootId, |
20 | module_id: ModuleId, | 20 | module_id: ModuleId, |
21 | ) -> Cancelable<Self> { | 21 | ) -> Self { |
22 | let module_tree = db.module_tree(source_root_id); | 22 | let module_tree = db.module_tree(source_root_id); |
23 | let def_loc = DefLoc { | 23 | let def_loc = DefLoc { |
24 | kind: DefKind::Module, | 24 | kind: DefKind::Module, |
@@ -27,8 +27,7 @@ impl Module { | |||
27 | source_item_id: module_id.source(&module_tree), | 27 | source_item_id: module_id.source(&module_tree), |
28 | }; | 28 | }; |
29 | let def_id = def_loc.id(db); | 29 | let def_id = def_loc.id(db); |
30 | let module = Module::new(def_id); | 30 | Module::new(def_id) |
31 | Ok(module) | ||
32 | } | 31 | } |
33 | 32 | ||
34 | pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | 33 | pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { |
@@ -84,15 +83,15 @@ impl Module { | |||
84 | let loc = self.def_id.loc(db); | 83 | let loc = self.def_id.loc(db); |
85 | let module_tree = db.module_tree(loc.source_root_id); | 84 | let module_tree = db.module_tree(loc.source_root_id); |
86 | let module_id = loc.module_id.crate_root(&module_tree); | 85 | let module_id = loc.module_id.crate_root(&module_tree); |
87 | Module::from_module_id(db, loc.source_root_id, module_id) | 86 | Ok(Module::from_module_id(db, loc.source_root_id, module_id)) |
88 | } | 87 | } |
89 | 88 | ||
90 | /// Finds a child module with the specified name. | 89 | /// Finds a child module with the specified name. |
91 | pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { | 90 | pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { |
92 | let loc = self.def_id.loc(db); | 91 | let loc = self.def_id.loc(db); |
93 | let module_tree = db.module_tree(loc.source_root_id); | 92 | let module_tree = db.module_tree(loc.source_root_id); |
94 | let child_id = ctry!(loc.module_id.child(&module_tree, name)); | 93 | let child_id = loc.module_id.child(&module_tree, name)?; |
95 | Module::from_module_id(db, loc.source_root_id, child_id).map(Some) | 94 | Some(Module::from_module_id(db, loc.source_root_id, child_id)) |
96 | } | 95 | } |
97 | 96 | ||
98 | /// Iterates over all child modules. | 97 | /// Iterates over all child modules. |
@@ -106,7 +105,7 @@ impl Module { | |||
106 | .module_id | 105 | .module_id |
107 | .children(&module_tree) | 106 | .children(&module_tree) |
108 | .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) | 107 | .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) |
109 | .collect::<Cancelable<Vec<_>>>()?; | 108 | .collect::<Vec<_>>(); |
110 | Ok(children.into_iter()) | 109 | Ok(children.into_iter()) |
111 | } | 110 | } |
112 | 111 | ||
@@ -114,7 +113,11 @@ impl Module { | |||
114 | let loc = self.def_id.loc(db); | 113 | let loc = self.def_id.loc(db); |
115 | let module_tree = db.module_tree(loc.source_root_id); | 114 | let module_tree = db.module_tree(loc.source_root_id); |
116 | let parent_id = ctry!(loc.module_id.parent(&module_tree)); | 115 | let parent_id = ctry!(loc.module_id.parent(&module_tree)); |
117 | Module::from_module_id(db, loc.source_root_id, parent_id).map(Some) | 116 | Ok(Some(Module::from_module_id( |
117 | db, | ||
118 | loc.source_root_id, | ||
119 | parent_id, | ||
120 | ))) | ||
118 | } | 121 | } |
119 | 122 | ||
120 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 123 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 68c3eb4e4..3b2498d5a 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -82,7 +82,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
82 | use fn crate::module_tree::Submodule::submodules_query; | 82 | use fn crate::module_tree::Submodule::submodules_query; |
83 | } | 83 | } |
84 | 84 | ||
85 | fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> { | 85 | fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<InputModuleItems> { |
86 | type InputModuleItemsQuery; | 86 | type InputModuleItemsQuery; |
87 | use fn query_definitions::input_module_items; | 87 | use fn query_definitions::input_module_items; |
88 | } | 88 | } |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 316896dce..d7cc9b4ca 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -163,7 +163,7 @@ impl DefId { | |||
163 | let loc = self.loc(db); | 163 | let loc = self.loc(db); |
164 | let res = match loc.kind { | 164 | let res = match loc.kind { |
165 | DefKind::Module => { | 165 | DefKind::Module => { |
166 | let module = Module::from_module_id(db, loc.source_root_id, loc.module_id)?; | 166 | let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); |
167 | Def::Module(module) | 167 | Def::Module(module) |
168 | } | 168 | } |
169 | DefKind::Function => { | 169 | DefKind::Function => { |
@@ -208,7 +208,11 @@ impl DefId { | |||
208 | /// For a module, returns that module; for any other def, returns the containing module. | 208 | /// For a module, returns that module; for any other def, returns the containing module. |
209 | pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { | 209 | pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { |
210 | let loc = self.loc(db); | 210 | let loc = self.loc(db); |
211 | Module::from_module_id(db, loc.source_root_id, loc.module_id) | 211 | Ok(Module::from_module_id( |
212 | db, | ||
213 | loc.source_root_id, | ||
214 | loc.module_id, | ||
215 | )) | ||
212 | } | 216 | } |
213 | 217 | ||
214 | /// Returns the containing crate. | 218 | /// Returns the containing crate. |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index d0b086308..c9a9fb99f 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -196,7 +196,7 @@ pub(crate) fn impls_in_module( | |||
196 | module_id: ModuleId, | 196 | module_id: ModuleId, |
197 | ) -> Cancelable<Arc<ModuleImplBlocks>> { | 197 | ) -> Cancelable<Arc<ModuleImplBlocks>> { |
198 | let mut result = ModuleImplBlocks::new(); | 198 | let mut result = ModuleImplBlocks::new(); |
199 | let module = Module::from_module_id(db, source_root_id, module_id)?; | 199 | let module = Module::from_module_id(db, source_root_id, module_id); |
200 | result.collect(db, module)?; | 200 | result.collect(db, module)?; |
201 | Ok(Arc::new(result)) | 201 | Ok(Arc::new(result)) |
202 | } | 202 | } |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 647fd92aa..ea8ab4c83 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -15,9 +15,7 @@ use crate::{ | |||
15 | fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { | 15 | fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { |
16 | let (db, pos) = MockDatabase::with_position(fixture); | 16 | let (db, pos) = MockDatabase::with_position(fixture); |
17 | let source_root = db.file_source_root(pos.file_id); | 17 | let source_root = db.file_source_root(pos.file_id); |
18 | let module = crate::source_binder::module_from_position(&db, pos) | 18 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); |
19 | .unwrap() | ||
20 | .unwrap(); | ||
21 | let module_id = module.def_id.loc(&db).module_id; | 19 | let module_id = module.def_id.loc(&db).module_id; |
22 | (db.item_map(source_root).unwrap(), module_id) | 20 | (db.item_map(source_root).unwrap(), module_id) |
23 | } | 21 | } |
@@ -242,9 +240,7 @@ fn item_map_across_crates() { | |||
242 | db.set_crate_graph(crate_graph); | 240 | db.set_crate_graph(crate_graph); |
243 | 241 | ||
244 | let source_root = db.file_source_root(main_id); | 242 | let source_root = db.file_source_root(main_id); |
245 | let module = crate::source_binder::module_from_file_id(&db, main_id) | 243 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
246 | .unwrap() | ||
247 | .unwrap(); | ||
248 | let module_id = module.def_id.loc(&db).module_id; | 244 | let module_id = module.def_id.loc(&db).module_id; |
249 | let item_map = db.item_map(source_root).unwrap(); | 245 | let item_map = db.item_map(source_root).unwrap(); |
250 | 246 | ||
@@ -296,9 +292,7 @@ fn import_across_source_roots() { | |||
296 | 292 | ||
297 | db.set_crate_graph(crate_graph); | 293 | db.set_crate_graph(crate_graph); |
298 | 294 | ||
299 | let module = crate::source_binder::module_from_file_id(&db, main_id) | 295 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
300 | .unwrap() | ||
301 | .unwrap(); | ||
302 | let module_id = module.def_id.loc(&db).module_id; | 296 | let module_id = module.def_id.loc(&db).module_id; |
303 | let item_map = db.item_map(source_root).unwrap(); | 297 | let item_map = db.item_map(source_root).unwrap(); |
304 | 298 | ||
@@ -341,9 +335,7 @@ fn reexport_across_crates() { | |||
341 | db.set_crate_graph(crate_graph); | 335 | db.set_crate_graph(crate_graph); |
342 | 336 | ||
343 | let source_root = db.file_source_root(main_id); | 337 | let source_root = db.file_source_root(main_id); |
344 | let module = crate::source_binder::module_from_file_id(&db, main_id) | 338 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
345 | .unwrap() | ||
346 | .unwrap(); | ||
347 | let module_id = module.def_id.loc(&db).module_id; | 339 | let module_id = module.def_id.loc(&db).module_id; |
348 | let item_map = db.item_map(source_root).unwrap(); | 340 | let item_map = db.item_map(source_root).unwrap(); |
349 | 341 | ||
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index d84efbf95..7ff942f6a 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -47,7 +47,7 @@ pub(super) fn input_module_items( | |||
47 | db: &impl HirDatabase, | 47 | db: &impl HirDatabase, |
48 | source_root_id: SourceRootId, | 48 | source_root_id: SourceRootId, |
49 | module_id: ModuleId, | 49 | module_id: ModuleId, |
50 | ) -> Cancelable<Arc<InputModuleItems>> { | 50 | ) -> Arc<InputModuleItems> { |
51 | let module_tree = db.module_tree(source_root_id); | 51 | let module_tree = db.module_tree(source_root_id); |
52 | let source = module_id.source(&module_tree); | 52 | let source = module_id.source(&module_tree); |
53 | let file_id = source.file_id; | 53 | let file_id = source.file_id; |
@@ -90,7 +90,7 @@ pub(super) fn input_module_items( | |||
90 | } | 90 | } |
91 | } | 91 | } |
92 | }; | 92 | }; |
93 | Ok(Arc::new(res)) | 93 | Arc::new(res) |
94 | } | 94 | } |
95 | 95 | ||
96 | pub(super) fn item_map( | 96 | pub(super) fn item_map( |
@@ -101,11 +101,8 @@ pub(super) fn item_map( | |||
101 | let module_tree = db.module_tree(source_root); | 101 | let module_tree = db.module_tree(source_root); |
102 | let input = module_tree | 102 | let input = module_tree |
103 | .modules() | 103 | .modules() |
104 | .map(|id| { | 104 | .map(|id| (id, db.input_module_items(source_root, id))) |
105 | let items = db.input_module_items(source_root, id)?; | 105 | .collect::<FxHashMap<_, _>>(); |
106 | Ok((id, items)) | ||
107 | }) | ||
108 | .collect::<Cancelable<FxHashMap<_, _>>>()?; | ||
109 | 106 | ||
110 | let resolver = Resolver::new(db, &input, source_root, module_tree); | 107 | let resolver = Resolver::new(db, &input, source_root, module_tree); |
111 | let res = resolver.resolve()?; | 108 | let res = resolver.resolve()?; |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 70dd850d7..7ab8eeae2 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -5,7 +5,7 @@ | |||
5 | /// | 5 | /// |
6 | /// So, this modules should not be used during hir construction, it exists | 6 | /// So, this modules should not be used during hir construction, it exists |
7 | /// purely for "IDE needs". | 7 | /// purely for "IDE needs". |
8 | use ra_db::{FileId, FilePosition, Cancelable}; | 8 | use ra_db::{FileId, FilePosition}; |
9 | use ra_syntax::{ | 9 | use ra_syntax::{ |
10 | SmolStr, TextRange, SyntaxNode, | 10 | SmolStr, TextRange, SyntaxNode, |
11 | ast::{self, AstNode, NameOwner}, | 11 | ast::{self, AstNode, NameOwner}, |
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | }; | 18 | }; |
19 | 19 | ||
20 | /// Locates the module by `FileId`. Picks topmost module in the file. | 20 | /// Locates the module by `FileId`. Picks topmost module in the file. |
21 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> { | 21 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Option<Module> { |
22 | let module_source = SourceItemId { | 22 | let module_source = SourceItemId { |
23 | file_id: file_id.into(), | 23 | file_id: file_id.into(), |
24 | item_id: None, | 24 | item_id: None, |
@@ -31,25 +31,22 @@ pub fn module_from_declaration( | |||
31 | db: &impl HirDatabase, | 31 | db: &impl HirDatabase, |
32 | file_id: FileId, | 32 | file_id: FileId, |
33 | decl: &ast::Module, | 33 | decl: &ast::Module, |
34 | ) -> Cancelable<Option<Module>> { | 34 | ) -> Option<Module> { |
35 | let parent_module = module_from_file_id(db, file_id)?; | 35 | let parent_module = module_from_file_id(db, file_id); |
36 | let child_name = decl.name(); | 36 | let child_name = decl.name(); |
37 | match (parent_module, child_name) { | 37 | match (parent_module, child_name) { |
38 | (Some(parent_module), Some(child_name)) => { | 38 | (Some(parent_module), Some(child_name)) => { |
39 | if let Some(child) = parent_module.child(db, &child_name.as_name())? { | 39 | if let Some(child) = parent_module.child(db, &child_name.as_name()) { |
40 | return Ok(Some(child)); | 40 | return Some(child); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | _ => (), | 43 | _ => (), |
44 | } | 44 | } |
45 | Ok(None) | 45 | None |
46 | } | 46 | } |
47 | 47 | ||
48 | /// Locates the module by position in the source code. | 48 | /// Locates the module by position in the source code. |
49 | pub fn module_from_position( | 49 | pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Module> { |
50 | db: &impl HirDatabase, | ||
51 | position: FilePosition, | ||
52 | ) -> Cancelable<Option<Module>> { | ||
53 | let file = db.source_file(position.file_id); | 50 | let file = db.source_file(position.file_id); |
54 | match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) { | 51 | match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) { |
55 | Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m), | 52 | Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m), |
@@ -61,7 +58,7 @@ fn module_from_inline( | |||
61 | db: &impl HirDatabase, | 58 | db: &impl HirDatabase, |
62 | file_id: FileId, | 59 | file_id: FileId, |
63 | module: &ast::Module, | 60 | module: &ast::Module, |
64 | ) -> Cancelable<Option<Module>> { | 61 | ) -> Option<Module> { |
65 | assert!(!module.has_semi()); | 62 | assert!(!module.has_semi()); |
66 | let file_id = file_id.into(); | 63 | let file_id = file_id.into(); |
67 | let file_items = db.file_items(file_id); | 64 | let file_items = db.file_items(file_id); |
@@ -78,7 +75,7 @@ pub fn module_from_child_node( | |||
78 | db: &impl HirDatabase, | 75 | db: &impl HirDatabase, |
79 | file_id: FileId, | 76 | file_id: FileId, |
80 | child: &SyntaxNode, | 77 | child: &SyntaxNode, |
81 | ) -> Cancelable<Option<Module>> { | 78 | ) -> Option<Module> { |
82 | if let Some(m) = child | 79 | if let Some(m) = child |
83 | .ancestors() | 80 | .ancestors() |
84 | .filter_map(ast::Module::cast) | 81 | .filter_map(ast::Module::cast) |
@@ -90,22 +87,16 @@ pub fn module_from_child_node( | |||
90 | } | 87 | } |
91 | } | 88 | } |
92 | 89 | ||
93 | fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable<Option<Module>> { | 90 | fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> { |
94 | let source_root_id = db.file_source_root(source.file_id.as_original_file()); | 91 | let source_root_id = db.file_source_root(source.file_id.as_original_file()); |
95 | let module_tree = db.module_tree(source_root_id); | 92 | let module_tree = db.module_tree(source_root_id); |
96 | let module_id = ctry!(module_tree.find_module_by_source(source)); | 93 | let module_id = module_tree.find_module_by_source(source)?; |
97 | Ok(Some(Module::from_module_id(db, source_root_id, module_id)?)) | 94 | Some(Module::from_module_id(db, source_root_id, module_id)) |
98 | } | 95 | } |
99 | 96 | ||
100 | pub fn function_from_position( | 97 | pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> { |
101 | db: &impl HirDatabase, | ||
102 | position: FilePosition, | ||
103 | ) -> Cancelable<Option<Function>> { | ||
104 | let file = db.source_file(position.file_id); | 98 | let file = db.source_file(position.file_id); |
105 | let fn_def = ctry!(find_node_at_offset::<ast::FnDef>( | 99 | let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), position.offset)?; |
106 | file.syntax(), | ||
107 | position.offset | ||
108 | )); | ||
109 | function_from_source(db, position.file_id, fn_def) | 100 | function_from_source(db, position.file_id, fn_def) |
110 | } | 101 | } |
111 | 102 | ||
@@ -113,10 +104,10 @@ pub fn function_from_source( | |||
113 | db: &impl HirDatabase, | 104 | db: &impl HirDatabase, |
114 | file_id: FileId, | 105 | file_id: FileId, |
115 | fn_def: &ast::FnDef, | 106 | fn_def: &ast::FnDef, |
116 | ) -> Cancelable<Option<Function>> { | 107 | ) -> Option<Function> { |
117 | let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); | 108 | let module = module_from_child_node(db, file_id, fn_def.syntax())?; |
118 | let res = function_from_module(db, &module, fn_def); | 109 | let res = function_from_module(db, &module, fn_def); |
119 | Ok(Some(res)) | 110 | Some(res) |
120 | } | 111 | } |
121 | 112 | ||
122 | pub fn function_from_module( | 113 | pub fn function_from_module( |
@@ -145,21 +136,18 @@ pub fn function_from_child_node( | |||
145 | db: &impl HirDatabase, | 136 | db: &impl HirDatabase, |
146 | file_id: FileId, | 137 | file_id: FileId, |
147 | node: &SyntaxNode, | 138 | node: &SyntaxNode, |
148 | ) -> Cancelable<Option<Function>> { | 139 | ) -> Option<Function> { |
149 | let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast)); | 140 | let fn_def = node.ancestors().find_map(ast::FnDef::cast)?; |
150 | function_from_source(db, file_id, fn_def) | 141 | function_from_source(db, file_id, fn_def) |
151 | } | 142 | } |
152 | 143 | ||
153 | pub fn macro_symbols( | 144 | pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> { |
154 | db: &impl HirDatabase, | 145 | let module = match module_from_file_id(db, file_id) { |
155 | file_id: FileId, | ||
156 | ) -> Cancelable<Vec<(SmolStr, TextRange)>> { | ||
157 | let module = match module_from_file_id(db, file_id)? { | ||
158 | Some(it) => it, | 146 | Some(it) => it, |
159 | None => return Ok(Vec::new()), | 147 | None => return Vec::new(), |
160 | }; | 148 | }; |
161 | let loc = module.def_id.loc(db); | 149 | let loc = module.def_id.loc(db); |
162 | let items = db.input_module_items(loc.source_root_id, loc.module_id)?; | 150 | let items = db.input_module_items(loc.source_root_id, loc.module_id); |
163 | let mut res = Vec::new(); | 151 | let mut res = Vec::new(); |
164 | 152 | ||
165 | for macro_call_id in items | 153 | for macro_call_id in items |
@@ -184,5 +172,5 @@ pub fn macro_symbols( | |||
184 | } | 172 | } |
185 | } | 173 | } |
186 | 174 | ||
187 | Ok(res) | 175 | res |
188 | } | 176 | } |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 8aacb1a7f..b81d91e80 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -320,9 +320,7 @@ fn infer(content: &str) -> String { | |||
320 | .descendants() | 320 | .descendants() |
321 | .filter_map(ast::FnDef::cast) | 321 | .filter_map(ast::FnDef::cast) |
322 | { | 322 | { |
323 | let func = source_binder::function_from_source(&db, file_id, fn_def) | 323 | let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); |
324 | .unwrap() | ||
325 | .unwrap(); | ||
326 | let inference_result = func.infer(&db).unwrap(); | 324 | let inference_result = func.infer(&db).unwrap(); |
327 | let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); | 325 | let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); |
328 | let mut types = Vec::new(); | 326 | let mut types = Vec::new(); |
@@ -404,9 +402,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | |||
404 | } | 402 | } |
405 | ", | 403 | ", |
406 | ); | 404 | ); |
407 | let func = source_binder::function_from_position(&db, pos) | 405 | let func = source_binder::function_from_position(&db, pos).unwrap(); |
408 | .unwrap() | ||
409 | .unwrap(); | ||
410 | { | 406 | { |
411 | let events = db.log_executed(|| { | 407 | let events = db.log_executed(|| { |
412 | func.infer(&db).unwrap(); | 408 | func.infer(&db).unwrap(); |