Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/lib.rs')
-rw-r--r--crates/hir-def/src/lib.rs38
1 files changed, 21 insertions, 17 deletions
diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs
index d63f2268aa..828842de7e 100644
--- a/crates/hir-def/src/lib.rs
+++ b/crates/hir-def/src/lib.rs
@@ -90,7 +90,7 @@ use hir_expand::{
use item_tree::ExternBlock;
use la_arena::Idx;
use nameres::DefMap;
-use span::{AstIdNode, FileAstId, FileId, Span};
+use span::{AstIdNode, FileAstId, FileId, SyntaxContextId};
use stdx::impl_from;
use syntax::{ast, AstNode};
@@ -1342,21 +1342,22 @@ impl AsMacroCall for InFile<&ast::MacroCall> {
let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value));
let span_map = db.span_map(self.file_id);
let path = self.value.path().and_then(|path| {
- path::ModPath::from_src(db, path, &mut |range| {
+ let range = path.syntax().text_range();
+ let mod_path = path::ModPath::from_src(db, path, &mut |range| {
span_map.as_ref().span_for_range(range).ctx
- })
+ })?;
+ let call_site = span_map.span_for_range(range);
+ Some((call_site, mod_path))
});
- let Some(path) = path else {
+ let Some((call_site, path)) = path else {
return Ok(ExpandResult::only_err(ExpandError::other("malformed macro invocation")));
};
- let call_site = span_map.span_for_range(self.value.syntax().text_range());
-
macro_call_as_call_id_with_eager(
db,
&AstIdWithPath::new(ast_id.file_id, ast_id.value, path),
- call_site,
+ call_site.ctx,
expands_to,
krate,
resolver,
@@ -1381,7 +1382,7 @@ impl<T: AstIdNode> AstIdWithPath<T> {
fn macro_call_as_call_id(
db: &dyn ExpandDatabase,
call: &AstIdWithPath<ast::MacroCall>,
- call_site: Span,
+ call_site: SyntaxContextId,
expand_to: ExpandTo,
krate: CrateId,
resolver: impl Fn(path::ModPath) -> Option<MacroDefId> + Copy,
@@ -1393,7 +1394,7 @@ fn macro_call_as_call_id(
fn macro_call_as_call_id_with_eager(
db: &dyn ExpandDatabase,
call: &AstIdWithPath<ast::MacroCall>,
- call_site: Span,
+ call_site: SyntaxContextId,
expand_to: ExpandTo,
krate: CrateId,
resolver: impl FnOnce(path::ModPath) -> Option<MacroDefId>,
@@ -1403,17 +1404,20 @@ fn macro_call_as_call_id_with_eager(
resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?;
let res = match def.kind {
- MacroDefKind::BuiltInEager(..) => {
- let macro_call = InFile::new(call.ast_id.file_id, call.ast_id.to_node(db));
- expand_eager_macro_input(db, krate, macro_call, def, call_site, &|path| {
- eager_resolver(path).filter(MacroDefId::is_fn_like)
- })
- }
+ MacroDefKind::BuiltInEager(..) => expand_eager_macro_input(
+ db,
+ krate,
+ &call.ast_id.to_node(db),
+ call.ast_id,
+ def,
+ call_site,
+ &|path| eager_resolver(path).filter(MacroDefId::is_fn_like),
+ ),
_ if def.is_fn_like() => ExpandResult {
- value: Some(def.as_lazy_macro(
+ value: Some(def.make_call(
db,
krate,
- MacroCallKind::FnLike { ast_id: call.ast_id, expand_to },
+ MacroCallKind::FnLike { ast_id: call.ast_id, expand_to, eager: None },
call_site,
)),
err: None,