diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/body.rs | 19 | ||||
-rw-r--r-- | crates/hir_def/src/body/lower.rs | 16 | ||||
-rw-r--r-- | crates/hir_def/src/data.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/block.rs | 4 |
4 files changed, 19 insertions, 22 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 2c2c999dd..8e8c0271f 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs | |||
@@ -45,7 +45,7 @@ pub(crate) struct CfgExpander { | |||
45 | 45 | ||
46 | pub(crate) struct Expander { | 46 | pub(crate) struct Expander { |
47 | cfg_expander: CfgExpander, | 47 | cfg_expander: CfgExpander, |
48 | crate_def_map: Arc<DefMap>, | 48 | def_map: Arc<DefMap>, |
49 | current_file_id: HirFileId, | 49 | current_file_id: HirFileId, |
50 | ast_id_map: Arc<AstIdMap>, | 50 | ast_id_map: Arc<AstIdMap>, |
51 | module: ModuleId, | 51 | module: ModuleId, |
@@ -90,7 +90,7 @@ impl Expander { | |||
90 | let ast_id_map = db.ast_id_map(current_file_id); | 90 | let ast_id_map = db.ast_id_map(current_file_id); |
91 | Expander { | 91 | Expander { |
92 | cfg_expander, | 92 | cfg_expander, |
93 | crate_def_map, | 93 | def_map: crate_def_map, |
94 | current_file_id, | 94 | current_file_id, |
95 | ast_id_map, | 95 | ast_id_map, |
96 | module, | 96 | module, |
@@ -101,7 +101,6 @@ impl Expander { | |||
101 | pub(crate) fn enter_expand<T: ast::AstNode>( | 101 | pub(crate) fn enter_expand<T: ast::AstNode>( |
102 | &mut self, | 102 | &mut self, |
103 | db: &dyn DefDatabase, | 103 | db: &dyn DefDatabase, |
104 | local_scope: Option<&ItemScope>, | ||
105 | macro_call: ast::MacroCall, | 104 | macro_call: ast::MacroCall, |
106 | ) -> ExpandResult<Option<(Mark, T)>> { | 105 | ) -> ExpandResult<Option<(Mark, T)>> { |
107 | if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { | 106 | if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { |
@@ -111,18 +110,12 @@ impl Expander { | |||
111 | 110 | ||
112 | let macro_call = InFile::new(self.current_file_id, ¯o_call); | 111 | let macro_call = InFile::new(self.current_file_id, ¯o_call); |
113 | 112 | ||
114 | let resolver = |path: ModPath| -> Option<MacroDefId> { | 113 | let resolver = |
115 | if let Some(local_scope) = local_scope { | 114 | |path: ModPath| -> Option<MacroDefId> { self.resolve_path_as_macro(db, &path) }; |
116 | if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) { | ||
117 | return Some(def); | ||
118 | } | ||
119 | } | ||
120 | self.resolve_path_as_macro(db, &path) | ||
121 | }; | ||
122 | 115 | ||
123 | let mut err = None; | 116 | let mut err = None; |
124 | let call_id = | 117 | let call_id = |
125 | macro_call.as_call_id_with_errors(db, self.crate_def_map.krate(), resolver, &mut |e| { | 118 | macro_call.as_call_id_with_errors(db, self.def_map.krate(), resolver, &mut |e| { |
126 | err.get_or_insert(e); | 119 | err.get_or_insert(e); |
127 | }); | 120 | }); |
128 | let call_id = match call_id { | 121 | let call_id = match call_id { |
@@ -203,7 +196,7 @@ impl Expander { | |||
203 | } | 196 | } |
204 | 197 | ||
205 | fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { | 198 | fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { |
206 | self.crate_def_map | 199 | self.def_map |
207 | .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) | 200 | .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) |
208 | .0 | 201 | .0 |
209 | .take_macros() | 202 | .take_macros() |
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 4ce5e5b72..2c8a86723 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` | 1 | //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` |
2 | //! representation. | 2 | //! representation. |
3 | 3 | ||
4 | use std::{any::type_name, sync::Arc}; | 4 | use std::{any::type_name, mem, sync::Arc}; |
5 | 5 | ||
6 | use either::Either; | 6 | use either::Either; |
7 | use hir_expand::{ | 7 | use hir_expand::{ |
@@ -559,7 +559,7 @@ impl ExprCollector<'_> { | |||
559 | let outer_file = self.expander.current_file_id; | 559 | let outer_file = self.expander.current_file_id; |
560 | 560 | ||
561 | let macro_call = self.expander.to_source(AstPtr::new(&e)); | 561 | let macro_call = self.expander.to_source(AstPtr::new(&e)); |
562 | let res = self.expander.enter_expand(self.db, Some(&self.body.item_scope), e); | 562 | let res = self.expander.enter_expand(self.db, e); |
563 | 563 | ||
564 | match &res.err { | 564 | match &res.err { |
565 | Some(ExpandError::UnresolvedProcMacro) => { | 565 | Some(ExpandError::UnresolvedProcMacro) => { |
@@ -696,11 +696,19 @@ impl ExprCollector<'_> { | |||
696 | 696 | ||
697 | fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId { | 697 | fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId { |
698 | let syntax_node_ptr = AstPtr::new(&block.clone().into()); | 698 | let syntax_node_ptr = AstPtr::new(&block.clone().into()); |
699 | let ast_id = self.expander.ast_id(&block); | ||
700 | let def_map = self.db.block_def_map(self.expander.module.krate, ast_id); | ||
701 | let prev_def_map = mem::replace(&mut self.expander.def_map, def_map); | ||
702 | |||
699 | self.collect_stmts_items(block.statements()); | 703 | self.collect_stmts_items(block.statements()); |
700 | let statements = | 704 | let statements = |
701 | block.statements().filter_map(|s| self.collect_stmt(s)).flatten().collect(); | 705 | block.statements().filter_map(|s| self.collect_stmt(s)).flatten().collect(); |
702 | let tail = block.tail_expr().map(|e| self.collect_expr(e)); | 706 | let tail = block.tail_expr().map(|e| self.collect_expr(e)); |
703 | self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr) | 707 | let expr_id = |
708 | self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr); | ||
709 | |||
710 | self.expander.def_map = prev_def_map; | ||
711 | expr_id | ||
704 | } | 712 | } |
705 | 713 | ||
706 | fn collect_stmts_items(&mut self, stmts: ast::AstChildren<ast::Stmt>) { | 714 | fn collect_stmts_items(&mut self, stmts: ast::AstChildren<ast::Stmt>) { |
@@ -830,7 +838,7 @@ impl ExprCollector<'_> { | |||
830 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { | 838 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { |
831 | // This could also be a single-segment path pattern. To | 839 | // This could also be a single-segment path pattern. To |
832 | // decide that, we need to try resolving the name. | 840 | // decide that, we need to try resolving the name. |
833 | let (resolved, _) = self.expander.crate_def_map.resolve_path( | 841 | let (resolved, _) = self.expander.def_map.resolve_path( |
834 | self.db, | 842 | self.db, |
835 | self.expander.module.local_id, | 843 | self.expander.module.local_id, |
836 | &name.clone().into(), | 844 | &name.clone().into(), |
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index e7b7724f7..c2b0dc007 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs | |||
@@ -262,7 +262,7 @@ fn collect_items( | |||
262 | let root = db.parse_or_expand(file_id).unwrap(); | 262 | let root = db.parse_or_expand(file_id).unwrap(); |
263 | let call = ast_id_map.get(call.ast_id).to_node(&root); | 263 | let call = ast_id_map.get(call.ast_id).to_node(&root); |
264 | 264 | ||
265 | if let Some((mark, mac)) = expander.enter_expand(db, None, call).value { | 265 | if let Some((mark, mac)) = expander.enter_expand(db, call).value { |
266 | let src: InFile<ast::MacroItems> = expander.to_source(mac); | 266 | let src: InFile<ast::MacroItems> = expander.to_source(mac); |
267 | let item_tree = db.item_tree(src.file_id); | 267 | let item_tree = db.item_tree(src.file_id); |
268 | let iter = | 268 | let iter = |
diff --git a/crates/hir_def/src/nameres/tests/block.rs b/crates/hir_def/src/nameres/tests/block.rs index b6c007920..01d6326a7 100644 --- a/crates/hir_def/src/nameres/tests/block.rs +++ b/crates/hir_def/src/nameres/tests/block.rs | |||
@@ -4,7 +4,6 @@ use super::*; | |||
4 | fn inner_item_smoke() { | 4 | fn inner_item_smoke() { |
5 | check_at( | 5 | check_at( |
6 | r#" | 6 | r#" |
7 | //- /lib.rs | ||
8 | struct inner {} | 7 | struct inner {} |
9 | fn outer() { | 8 | fn outer() { |
10 | $0 | 9 | $0 |
@@ -25,7 +24,6 @@ fn outer() { | |||
25 | fn use_from_crate() { | 24 | fn use_from_crate() { |
26 | check_at( | 25 | check_at( |
27 | r#" | 26 | r#" |
28 | //- /lib.rs | ||
29 | struct Struct; | 27 | struct Struct; |
30 | fn outer() { | 28 | fn outer() { |
31 | use Struct; | 29 | use Struct; |
@@ -50,7 +48,6 @@ fn outer() { | |||
50 | fn merge_namespaces() { | 48 | fn merge_namespaces() { |
51 | check_at( | 49 | check_at( |
52 | r#" | 50 | r#" |
53 | //- /lib.rs | ||
54 | struct name {} | 51 | struct name {} |
55 | fn outer() { | 52 | fn outer() { |
56 | fn name() {} | 53 | fn name() {} |
@@ -75,7 +72,6 @@ fn outer() { | |||
75 | fn nested_blocks() { | 72 | fn nested_blocks() { |
76 | check_at( | 73 | check_at( |
77 | r#" | 74 | r#" |
78 | //- /lib.rs | ||
79 | fn outer() { | 75 | fn outer() { |
80 | struct inner1 {} | 76 | struct inner1 {} |
81 | fn inner() { | 77 | fn inner() { |