mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Expander: store a LocalModuleId, not ModuleId
It already stores the DefMap containing the module, so having a full ModuleId is unnecessary and makes it easier to mix things up
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
nameres::DefMap,
|
||||
path::{ModPath, Path},
|
||||
src::HasSource,
|
||||
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId,
|
||||
AsMacroCall, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId,
|
||||
};
|
||||
|
||||
/// A subset of Expander that only deals with cfg attributes. We only need it to
|
||||
@@ -49,7 +49,7 @@ pub(crate) struct Expander {
|
||||
def_map: Arc<DefMap>,
|
||||
current_file_id: HirFileId,
|
||||
ast_id_map: Arc<AstIdMap>,
|
||||
module: ModuleId,
|
||||
module: LocalModuleId,
|
||||
recursion_limit: usize,
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ pub(crate) fn new(
|
||||
def_map: crate_def_map,
|
||||
current_file_id,
|
||||
ast_id_map,
|
||||
module,
|
||||
module: module.local_id,
|
||||
recursion_limit: 0,
|
||||
}
|
||||
}
|
||||
@@ -197,10 +197,7 @@ fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
|
||||
}
|
||||
|
||||
fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> {
|
||||
self.def_map
|
||||
.resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other)
|
||||
.0
|
||||
.take_macros()
|
||||
self.def_map.resolve_path(db, self.module, path, BuiltinShadowMode::Other).0.take_macros()
|
||||
}
|
||||
|
||||
fn ast_id<N: AstNode>(&self, item: &N) -> AstId<N> {
|
||||
|
||||
@@ -698,15 +698,15 @@ fn collect_stmt(&mut self, s: ast::Stmt) -> Option<Vec<Statement>> {
|
||||
|
||||
fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId {
|
||||
let ast_id = self.expander.ast_id(&block);
|
||||
let block_loc = BlockLoc { ast_id, module: self.expander.module };
|
||||
let block_loc =
|
||||
BlockLoc { ast_id, module: self.expander.def_map.module_id(self.expander.module) };
|
||||
let block_id = self.db.intern_block(block_loc);
|
||||
let opt_def_map = self.db.block_def_map(block_id);
|
||||
let has_def_map = opt_def_map.is_some();
|
||||
let def_map = opt_def_map.unwrap_or_else(|| self.expander.def_map.clone());
|
||||
let module =
|
||||
if has_def_map { def_map.module_id(def_map.root()) } else { self.expander.module };
|
||||
let module = if has_def_map { def_map.root() } else { self.expander.module };
|
||||
let prev_def_map = mem::replace(&mut self.expander.def_map, def_map);
|
||||
let prev_module = mem::replace(&mut self.expander.module, module);
|
||||
let prev_local_module = mem::replace(&mut self.expander.module, module);
|
||||
|
||||
self.collect_stmts_items(block.statements());
|
||||
let statements =
|
||||
@@ -719,7 +719,7 @@ fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId {
|
||||
);
|
||||
|
||||
self.expander.def_map = prev_def_map;
|
||||
self.expander.module = prev_module;
|
||||
self.expander.module = prev_local_module;
|
||||
expr_id
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ fn collect_stmts_items(&mut self, stmts: ast::AstChildren<ast::Stmt>) {
|
||||
}
|
||||
Either::Right(e) => {
|
||||
let mac = MacroDefId {
|
||||
krate: self.expander.module.krate,
|
||||
krate: self.expander.def_map.krate(),
|
||||
ast_id: Some(self.expander.ast_id(&e)),
|
||||
kind: MacroDefKind::Declarative,
|
||||
local_inner: false,
|
||||
@@ -852,7 +852,7 @@ fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
|
||||
// decide that, we need to try resolving the name.
|
||||
let (resolved, _) = self.expander.def_map.resolve_path(
|
||||
self.db,
|
||||
self.expander.module.local_id,
|
||||
self.expander.module,
|
||||
&name.clone().into(),
|
||||
BuiltinShadowMode::Other,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user