diff options
Diffstat (limited to 'crates/hir_def/src/body.rs')
-rw-r--r-- | crates/hir_def/src/body.rs | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 344f0b6c0..ff4b4a0cf 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs | |||
@@ -17,6 +17,7 @@ use hir_expand::{ | |||
17 | HirFileId, InFile, MacroDefId, | 17 | HirFileId, InFile, MacroDefId, |
18 | }; | 18 | }; |
19 | use la_arena::{Arena, ArenaMap}; | 19 | use la_arena::{Arena, ArenaMap}; |
20 | use profile::Count; | ||
20 | use rustc_hash::FxHashMap; | 21 | use rustc_hash::FxHashMap; |
21 | use syntax::{ast, AstNode, AstPtr}; | 22 | use syntax::{ast, AstNode, AstPtr}; |
22 | use test_utils::mark; | 23 | use test_utils::mark; |
@@ -29,10 +30,10 @@ use crate::{ | |||
29 | expr::{Expr, ExprId, Label, LabelId, Pat, PatId}, | 30 | expr::{Expr, ExprId, Label, LabelId, Pat, PatId}, |
30 | item_scope::BuiltinShadowMode, | 31 | item_scope::BuiltinShadowMode, |
31 | item_scope::ItemScope, | 32 | item_scope::ItemScope, |
32 | nameres::CrateDefMap, | 33 | nameres::DefMap, |
33 | path::{ModPath, Path}, | 34 | path::{ModPath, Path}, |
34 | src::HasSource, | 35 | src::HasSource, |
35 | AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, | 36 | AsMacroCall, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId, |
36 | }; | 37 | }; |
37 | 38 | ||
38 | /// A subset of Expander that only deals with cfg attributes. We only need it to | 39 | /// A subset of Expander that only deals with cfg attributes. We only need it to |
@@ -45,10 +46,10 @@ pub(crate) struct CfgExpander { | |||
45 | 46 | ||
46 | pub(crate) struct Expander { | 47 | pub(crate) struct Expander { |
47 | cfg_expander: CfgExpander, | 48 | cfg_expander: CfgExpander, |
48 | crate_def_map: Arc<CrateDefMap>, | 49 | def_map: Arc<DefMap>, |
49 | current_file_id: HirFileId, | 50 | current_file_id: HirFileId, |
50 | ast_id_map: Arc<AstIdMap>, | 51 | ast_id_map: Arc<AstIdMap>, |
51 | module: ModuleId, | 52 | module: LocalModuleId, |
52 | recursion_limit: usize, | 53 | recursion_limit: usize, |
53 | } | 54 | } |
54 | 55 | ||
@@ -86,14 +87,14 @@ impl Expander { | |||
86 | module: ModuleId, | 87 | module: ModuleId, |
87 | ) -> Expander { | 88 | ) -> Expander { |
88 | let cfg_expander = CfgExpander::new(db, current_file_id, module.krate); | 89 | let cfg_expander = CfgExpander::new(db, current_file_id, module.krate); |
89 | let crate_def_map = db.crate_def_map(module.krate); | 90 | let crate_def_map = module.def_map(db); |
90 | let ast_id_map = db.ast_id_map(current_file_id); | 91 | let ast_id_map = db.ast_id_map(current_file_id); |
91 | Expander { | 92 | Expander { |
92 | cfg_expander, | 93 | cfg_expander, |
93 | crate_def_map, | 94 | def_map: crate_def_map, |
94 | current_file_id, | 95 | current_file_id, |
95 | ast_id_map, | 96 | ast_id_map, |
96 | module, | 97 | module: module.local_id, |
97 | recursion_limit: 0, | 98 | recursion_limit: 0, |
98 | } | 99 | } |
99 | } | 100 | } |
@@ -101,7 +102,6 @@ impl Expander { | |||
101 | pub(crate) fn enter_expand<T: ast::AstNode>( | 102 | pub(crate) fn enter_expand<T: ast::AstNode>( |
102 | &mut self, | 103 | &mut self, |
103 | db: &dyn DefDatabase, | 104 | db: &dyn DefDatabase, |
104 | local_scope: Option<&ItemScope>, | ||
105 | macro_call: ast::MacroCall, | 105 | macro_call: ast::MacroCall, |
106 | ) -> ExpandResult<Option<(Mark, T)>> { | 106 | ) -> ExpandResult<Option<(Mark, T)>> { |
107 | if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { | 107 | if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { |
@@ -111,25 +111,19 @@ impl Expander { | |||
111 | 111 | ||
112 | let macro_call = InFile::new(self.current_file_id, ¯o_call); | 112 | let macro_call = InFile::new(self.current_file_id, ¯o_call); |
113 | 113 | ||
114 | let resolver = |path: ModPath| -> Option<MacroDefId> { | 114 | let resolver = |
115 | if let Some(local_scope) = local_scope { | 115 | |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 | 116 | ||
123 | let mut err = None; | 117 | let mut err = None; |
124 | let call_id = | 118 | let call_id = |
125 | macro_call.as_call_id_with_errors(db, self.crate_def_map.krate, resolver, &mut |e| { | 119 | macro_call.as_call_id_with_errors(db, self.def_map.krate(), resolver, &mut |e| { |
126 | err.get_or_insert(e); | 120 | err.get_or_insert(e); |
127 | }); | 121 | }); |
128 | let call_id = match call_id { | 122 | let call_id = match call_id { |
129 | Some(it) => it, | 123 | Some(it) => it, |
130 | None => { | 124 | None => { |
131 | if err.is_none() { | 125 | if err.is_none() { |
132 | eprintln!("no error despite `as_call_id_with_errors` returning `None`"); | 126 | log::warn!("no error despite `as_call_id_with_errors` returning `None`"); |
133 | } | 127 | } |
134 | return ExpandResult { value: None, err }; | 128 | return ExpandResult { value: None, err }; |
135 | } | 129 | } |
@@ -203,10 +197,7 @@ impl Expander { | |||
203 | } | 197 | } |
204 | 198 | ||
205 | fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { | 199 | fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { |
206 | self.crate_def_map | 200 | self.def_map.resolve_path(db, self.module, path, BuiltinShadowMode::Other).0.take_macros() |
207 | .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) | ||
208 | .0 | ||
209 | .take_macros() | ||
210 | } | 201 | } |
211 | 202 | ||
212 | fn ast_id<N: AstNode>(&self, item: &N) -> AstId<N> { | 203 | fn ast_id<N: AstNode>(&self, item: &N) -> AstId<N> { |
@@ -237,6 +228,7 @@ pub struct Body { | |||
237 | /// The `ExprId` of the actual body expression. | 228 | /// The `ExprId` of the actual body expression. |
238 | pub body_expr: ExprId, | 229 | pub body_expr: ExprId, |
239 | pub item_scope: ItemScope, | 230 | pub item_scope: ItemScope, |
231 | _c: Count<Self>, | ||
240 | } | 232 | } |
241 | 233 | ||
242 | pub type ExprPtr = AstPtr<ast::Expr>; | 234 | pub type ExprPtr = AstPtr<ast::Expr>; |