Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/body/lower.rs')
| -rw-r--r-- | crates/hir-def/src/body/lower.rs | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index db619b97db..27dfe766d3 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -24,9 +24,10 @@ use syntax::{ }; use crate::{ - body::{Body, BodyDiagnostic, BodySourceMap, Expander, ExprPtr, LabelPtr, LowerCtx, PatPtr}, + body::{Body, BodyDiagnostic, BodySourceMap, ExprPtr, LabelPtr, PatPtr}, data::adt::StructKind, db::DefDatabase, + expander::Expander, hir::{ dummy_expr_id, Array, Binding, BindingAnnotation, BindingId, CaptureBy, ClosureKind, Expr, ExprId, Label, LabelId, Literal, MatchArm, Movability, Pat, PatId, RecordFieldPat, @@ -34,6 +35,8 @@ use crate::{ }, item_scope::BuiltinShadowMode, lang_item::LangItem, + lower::LowerCtx, + nameres::DefMap, path::{GenericArgs, Path}, type_ref::{Mutability, Rawness, TypeRef}, AdtId, BlockId, BlockLoc, ModuleDefId, UnresolvedMacro, @@ -50,6 +53,7 @@ pub(super) fn lower( ExprCollector { db, krate, + def_map: db.crate_def_map(krate), source_map: BodySourceMap::default(), ast_id_map: db.ast_id_map(expander.current_file_id), body: Body { @@ -75,6 +79,7 @@ pub(super) fn lower( struct ExprCollector<'a> { db: &'a dyn DefDatabase, expander: Expander, + def_map: Arc<DefMap>, ast_id_map: Arc<AstIdMap>, krate: CrateId, body: Body, @@ -777,7 +782,13 @@ impl ExprCollector<'_> { let outer_file = self.expander.current_file_id; let macro_call_ptr = self.expander.to_source(AstPtr::new(&mcall)); - let res = self.expander.enter_expand(self.db, mcall); + let module = self.expander.module.local_id; + let res = self.expander.enter_expand(self.db, mcall, |path| { + self.def_map + .resolve_path(self.db, module, &path, crate::item_scope::BuiltinShadowMode::Other) + .0 + .take_macros() + }); let res = match res { Ok(res) => res, @@ -944,10 +955,7 @@ impl ExprCollector<'_> { let block_id = if block_has_items { let file_local_id = self.ast_id_map.ast_id(&block); let ast_id = AstId::new(self.expander.current_file_id, file_local_id); - Some(self.db.intern_block(BlockLoc { - ast_id, - module: self.expander.def_map.module_id(self.expander.module), - })) + Some(self.db.intern_block(BlockLoc { ast_id, module: self.expander.module })) } else { None }; @@ -956,11 +964,11 @@ impl ExprCollector<'_> { match block_id.map(|block_id| (self.db.block_def_map(block_id), block_id)) { Some((def_map, block_id)) => { self.body.block_scopes.push(block_id); - (def_map.root(), def_map) + (def_map.module_id(def_map.root()), def_map) } - None => (self.expander.module, self.expander.def_map.clone()), + None => (self.expander.module, self.def_map.clone()), }; - let prev_def_map = mem::replace(&mut self.expander.def_map, def_map); + let prev_def_map = mem::replace(&mut self.def_map, def_map); let prev_local_module = mem::replace(&mut self.expander.module, module); let mut statements = Vec::new(); @@ -982,7 +990,7 @@ impl ExprCollector<'_> { let expr_id = self .alloc_expr(mk_block(block_id, statements.into_boxed_slice(), tail), syntax_node_ptr); - self.expander.def_map = prev_def_map; + self.def_map = prev_def_map; self.expander.module = prev_local_module; expr_id } @@ -1028,9 +1036,9 @@ impl ExprCollector<'_> { let (binding, pattern) = if is_simple_ident_pat { // This could also be a single-segment path pattern. To // decide that, we need to try resolving the name. - let (resolved, _) = self.expander.def_map.resolve_path( + let (resolved, _) = self.def_map.resolve_path( self.db, - self.expander.module, + self.expander.module.local_id, &name.clone().into(), BuiltinShadowMode::Other, ); |