Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/semantics.rs')
-rw-r--r--crates/hir/src/semantics.rs39
1 files changed, 6 insertions, 33 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 117d9c4920..0dac64d6f2 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -408,11 +408,7 @@ impl<'db> SemanticsImpl<'db> {
}
pub fn expand_macro_call(&self, macro_call: &ast::MacroCall) -> Option<InFile<SyntaxNode>> {
- let sa = self.analyze_no_infer(macro_call.syntax())?;
-
- let macro_call = InFile::new(sa.file_id, macro_call);
- let file_id = sa.expansion(self.db, macro_call)?;
-
+ let file_id = self.to_def(macro_call)?;
let node = self.parse_or_expand(file_id.into());
Some(InFile::new(file_id.into(), node))
}
@@ -434,10 +430,7 @@ impl<'db> SemanticsImpl<'db> {
&self,
macro_call: &ast::MacroCall,
) -> Option<ExpandResult<SyntaxNode>> {
- let sa = self.analyze_no_infer(macro_call.syntax())?;
-
- let macro_call = InFile::new(sa.file_id, macro_call);
- let file_id = sa.expansion(self.db, macro_call)?;
+ let file_id = self.to_def(macro_call)?;
let macro_call = self.db.lookup_intern_macro_call(file_id);
let skip = matches!(
@@ -574,9 +567,7 @@ impl<'db> SemanticsImpl<'db> {
speculative_args: &ast::TokenTree,
token_to_map: SyntaxToken,
) -> Option<(SyntaxNode, Vec<(SyntaxToken, u8)>)> {
- let analyzer = self.analyze_no_infer(actual_macro_call.syntax())?;
- let macro_call = InFile::new(analyzer.file_id, actual_macro_call);
- let macro_file = analyzer.expansion(self.db, macro_call)?;
+ let macro_file = self.to_def(actual_macro_call)?;
hir_expand::db::expand_speculative(
self.db,
macro_file,
@@ -1097,16 +1088,7 @@ impl<'db> SemanticsImpl<'db> {
let file_id = match m_cache.get(&mcall) {
Some(&it) => it,
None => {
- let it = token
- .parent()
- .and_then(|parent| {
- self.analyze_impl(
- InFile::new(expansion, &parent),
- None,
- false,
- )
- })?
- .expansion(self.db, mcall.as_ref())?;
+ let it = ast::MacroCall::to_def(self, mcall.as_ref())?;
m_cache.insert(mcall, it);
it
}
@@ -1551,9 +1533,6 @@ impl<'db> SemanticsImpl<'db> {
.and_then(|call| macro_call_to_macro_id(ctx, call))
.map(Into::into)
})
- .or_else(|| {
- self.analyze(macro_call.value.syntax())?.resolve_macro_call(self.db, macro_call)
- })
}
pub fn is_proc_macro_call(&self, macro_call: InFile<&ast::MacroCall>) -> bool {
@@ -1562,14 +1541,8 @@ impl<'db> SemanticsImpl<'db> {
}
pub fn resolve_macro_call_arm(&self, macro_call: &ast::MacroCall) -> Option<u32> {
- let sa = self.analyze(macro_call.syntax())?;
- self.db
- .parse_macro_expansion(
- sa.expansion(self.db, self.wrap_node_infile(macro_call.clone()).as_ref())?,
- )
- .value
- .1
- .matched_arm
+ let file_id = self.to_def(macro_call)?;
+ self.db.parse_macro_expansion(file_id).value.1.matched_arm
}
pub fn get_unsafe_ops(&self, def: DefWithBody) -> FxHashSet<ExprOrPatSource> {