Fix incorrect FileId
and remove broken shortcut
Apparently we were using the crate's root file instead of the file containing the block.
This commit is contained in:
parent
fa1b500d2f
commit
090b2f0e50
2 changed files with 9 additions and 16 deletions
|
@ -199,16 +199,10 @@ impl DefMap {
|
|||
|
||||
pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> {
|
||||
let block: BlockLoc = db.lookup_intern_block(block_id);
|
||||
let item_tree = db.item_tree(block.ast_id.file_id);
|
||||
let block_items = item_tree.inner_items_of_block(block.ast_id.value);
|
||||
|
||||
let parent = block.module.def_map(db);
|
||||
|
||||
if block_items.is_empty() {
|
||||
// If there are no inner items, nothing new is brought into scope, so we can just return
|
||||
// the parent DefMap. This keeps DefMap parent chains short.
|
||||
return parent;
|
||||
}
|
||||
// FIXME: It would be good to just return the parent map when the block has no items, but
|
||||
// we rely on `def_map.block` in a few places, which is `Some` for the inner `DefMap`.
|
||||
|
||||
let block_info =
|
||||
BlockInfo { block: block_id, parent, parent_module: block.module.local_id };
|
||||
|
@ -216,7 +210,7 @@ impl DefMap {
|
|||
let mut def_map = DefMap::empty(block.module.krate, block_info.parent.edition);
|
||||
def_map.block = Some(block_info);
|
||||
|
||||
let def_map = collector::collect_defs(db, def_map, Some(block.ast_id.value));
|
||||
let def_map = collector::collect_defs(db, def_map, Some(block.ast_id));
|
||||
Arc::new(def_map)
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ const FIXED_POINT_LIMIT: usize = 8192;
|
|||
pub(super) fn collect_defs(
|
||||
db: &dyn DefDatabase,
|
||||
mut def_map: DefMap,
|
||||
block: Option<FileAstId<ast::BlockExpr>>,
|
||||
block: Option<AstId<ast::BlockExpr>>,
|
||||
) -> DefMap {
|
||||
let crate_graph = db.crate_graph();
|
||||
|
||||
|
@ -261,11 +261,10 @@ impl DefCollector<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn seed_with_inner(&mut self, block: FileAstId<ast::BlockExpr>) {
|
||||
let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id;
|
||||
let item_tree = self.db.item_tree(file_id.into());
|
||||
fn seed_with_inner(&mut self, block: AstId<ast::BlockExpr>) {
|
||||
let item_tree = self.db.item_tree(block.file_id);
|
||||
let module_id = self.def_map.root;
|
||||
self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id };
|
||||
self.def_map.modules[module_id].origin = ModuleOrigin::BlockExpr { block };
|
||||
if item_tree
|
||||
.top_level_attrs(self.db, self.def_map.krate)
|
||||
.cfg()
|
||||
|
@ -275,11 +274,11 @@ impl DefCollector<'_> {
|
|||
def_collector: &mut *self,
|
||||
macro_depth: 0,
|
||||
module_id,
|
||||
file_id: file_id.into(),
|
||||
file_id: block.file_id,
|
||||
item_tree: &item_tree,
|
||||
mod_dir: ModDir::root(),
|
||||
}
|
||||
.collect(item_tree.inner_items_of_block(block));
|
||||
.collect(item_tree.inner_items_of_block(block.value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue