Skip to content

Commit 5a6010d

Browse files
committed
fix caller for effects in macro expansions
1 parent 56625c5 commit 5a6010d

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/macro_expand.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ pub fn handle_macro_expansion(
9191
debug!("Failed to resolve macro path.");
9292
continue;
9393
}
94-
let canonical_path =
95-
match file_resolver_expand.resolve_macro_def_path(&macro_call) {
96-
Some(cp) => cp,
97-
None => continue,
98-
};
94+
let canonical_path = match file_resolver_expand.resolve_macro_def(&macro_call) {
95+
Some(cp) => cp,
96+
None => continue,
97+
};
9998
let text_range = macro_call.syntax().text_range();
10099
let line_index =
101100
LineIndex::new(resolver.db().file_text(current_file_id).as_ref());

src/resolution/resolve.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! with the needed functionality.
55
66
use crate::resolution::name_resolution::{Resolver, ResolverImpl};
7+
use crate::resolution::util::canonical_path;
78

89
use super::hacky_resolver::HackyResolver;
910
use crate::effect::SrcLoc;
@@ -13,7 +14,7 @@ use anyhow::Result;
1314
use log::debug;
1415
use ra_ap_hir::HirFileId;
1516
use ra_ap_syntax::ast::MacroCall;
16-
use ra_ap_syntax::SyntaxNode;
17+
use ra_ap_syntax::{AstNode, SyntaxNode};
1718
use std::fmt::Display;
1819
use std::path::Path as FilePath;
1920
use syn::{self, spanned::Spanned};
@@ -117,14 +118,11 @@ impl<'a> FileResolver<'a> {
117118
Some((file_id, expanded_syntax))
118119
}
119120

120-
pub fn resolve_macro_def_path(
121-
&self,
122-
macro_call: &MacroCall,
123-
) -> Option<CanonicalPath> {
124-
let path = macro_call.path()?;
125-
let last_segment = path.segment()?.name_ref()?.text().to_string();
126-
let fake_ident = syn::Ident::new(&last_segment, proc_macro2::Span::call_site());
127-
Some(self.resolve_def(&fake_ident))
121+
pub fn resolve_macro_def(&self, macro_call: &MacroCall) -> Option<CanonicalPath> {
122+
let containing_fn =
123+
&macro_call.syntax().ancestors().find_map(ra_ap_syntax::ast::Fn::cast)?;
124+
let def = self.resolver.sems.to_def(containing_fn)?;
125+
canonical_path(&self.resolver.sems, self.resolver.sems.db, &def.into())
128126
}
129127

130128
fn resolve_core(&self, i: &syn::Ident) -> Result<CanonicalPath> {

0 commit comments

Comments
 (0)