diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2023-04-22 10:52:31 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2023-04-22 11:02:11 +0200 |
| commit | 2aa44c8e37b0230e05e0d8e32687685c28fb8f8d (patch) | |
| tree | 0529f1309b0c0e234b164557c1e2ee49ba5a4fbb | |
| parent | 9b835f334f2c61d66c8c6554ec90325992752ce3 (diff) | |
| download | rust-2aa44c8e37b0230e05e0d8e32687685c28fb8f8d.tar.gz rust-2aa44c8e37b0230e05e0d8e32687685c28fb8f8d.zip | |
internal: Don't reparse files when trying to expand assoc item macro calls
| -rw-r--r-- | crates/hir-def/src/data.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs index 73d4eebb85a..701cc29f4ea 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -14,6 +14,7 @@ use crate::{ db::DefDatabase, expander::{Expander, Mark}, item_tree::{self, AssocItem, FnFlags, ItemTree, ItemTreeId, ModItem, Param, TreeId}, + macro_call_as_call_id, macro_id_to_def_id, nameres::{ attr_resolution::ResolvedAttr, diagnostics::DefDiagnostic, @@ -639,18 +640,15 @@ impl<'a> AssocItemCollector<'a> { } AssocItem::MacroCall(call) => { let file_id = self.expander.current_file_id(); - let root = self.db.parse_or_expand(file_id); let call = &item_tree[call]; - - let ast_id_map = self.db.ast_id_map(file_id); - let macro_call = ast_id_map.get(call.ast_id).to_node(&root); - let _cx = stdx::panic_context::enter(format!( - "collect_items MacroCall: {macro_call}" - )); let module = self.expander.module.local_id; - if let Ok(res) = - self.expander.enter_expand::<ast::MacroItems>(self.db, macro_call, |path| { + if let Ok(Some(call_id)) = macro_call_as_call_id( + self.db.upcast(), + &AstIdWithPath::new(file_id, call.ast_id, Clone::clone(&call.path)), + call.expand_to, + self.expander.module.krate(), + |path| { self.def_map .resolve_path( self.db, @@ -660,8 +658,11 @@ impl<'a> AssocItemCollector<'a> { ) .0 .take_macros() - }) - { + .map(|it| macro_id_to_def_id(self.db, it)) + }, + ) { + let res = + self.expander.enter_expand_id::<ast::MacroItems>(self.db, call_id); self.collect_macro_items(res, &|| hir_expand::MacroCallKind::FnLike { ast_id: InFile::new(file_id, call.ast_id), expand_to: hir_expand::ExpandTo::Items, |
