diff options
Diffstat (limited to 'crates/ra_hir_def/src/body/lower.rs')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 852d5cda7..3ced648e5 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -36,6 +36,7 @@ use crate::{ | |||
36 | 36 | ||
37 | use super::{ExprSource, PatSource}; | 37 | use super::{ExprSource, PatSource}; |
38 | use ast::AstChildren; | 38 | use ast::AstChildren; |
39 | use rustc_hash::FxHashMap; | ||
39 | use std::sync::Arc; | 40 | use std::sync::Arc; |
40 | 41 | ||
41 | pub(crate) struct LowerCtx { | 42 | pub(crate) struct LowerCtx { |
@@ -74,7 +75,11 @@ pub(super) fn lower( | |||
74 | body_expr: dummy_expr_id(), | 75 | body_expr: dummy_expr_id(), |
75 | item_scope: Default::default(), | 76 | item_scope: Default::default(), |
76 | }, | 77 | }, |
77 | item_trees: vec![(expander.current_file_id, item_tree)], | 78 | item_trees: { |
79 | let mut map = FxHashMap::default(); | ||
80 | map.insert(expander.current_file_id, item_tree); | ||
81 | map | ||
82 | }, | ||
78 | expander, | 83 | expander, |
79 | } | 84 | } |
80 | .collect(params, body) | 85 | .collect(params, body) |
@@ -87,7 +92,7 @@ struct ExprCollector<'a> { | |||
87 | body: Body, | 92 | body: Body, |
88 | source_map: BodySourceMap, | 93 | source_map: BodySourceMap, |
89 | 94 | ||
90 | item_trees: Vec<(HirFileId, Arc<ItemTree>)>, | 95 | item_trees: FxHashMap<HirFileId, Arc<ItemTree>>, |
91 | } | 96 | } |
92 | 97 | ||
93 | impl ExprCollector<'_> { | 98 | impl ExprCollector<'_> { |
@@ -541,7 +546,7 @@ impl ExprCollector<'_> { | |||
541 | .insert(macro_call, self.expander.current_file_id); | 546 | .insert(macro_call, self.expander.current_file_id); |
542 | 547 | ||
543 | let item_tree = self.db.item_tree(self.expander.current_file_id); | 548 | let item_tree = self.db.item_tree(self.expander.current_file_id); |
544 | self.item_trees.push((self.expander.current_file_id, item_tree)); | 549 | self.item_trees.insert(self.expander.current_file_id, item_tree); |
545 | let id = self.collect_expr(expansion); | 550 | let id = self.collect_expr(expansion); |
546 | self.expander.exit(self.db, mark); | 551 | self.expander.exit(self.db, mark); |
547 | id | 552 | id |
@@ -557,11 +562,7 @@ impl ExprCollector<'_> { | |||
557 | } | 562 | } |
558 | 563 | ||
559 | fn find_inner_item<S: ItemTreeNode>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> { | 564 | fn find_inner_item<S: ItemTreeNode>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> { |
560 | let index = | 565 | let tree = &self.item_trees[&id.file_id]; |
561 | self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| { | ||
562 | panic!("couldn't find item tree for file {:?}", id.file_id); | ||
563 | }); | ||
564 | let tree = &self.item_trees[index].1; | ||
565 | 566 | ||
566 | // FIXME: This probably breaks with `use` items, since they produce multiple item tree nodes | 567 | // FIXME: This probably breaks with `use` items, since they produce multiple item tree nodes |
567 | 568 | ||