Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/source_analyzer.rs')
-rw-r--r--crates/hir/src/source_analyzer.rs41
1 files changed, 10 insertions, 31 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index d229584064..8e71a54f80 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -24,11 +24,12 @@ use hir_def::{
LocalFieldId, Lookup, ModuleDefId, TraitId, VariantId,
};
use hir_expand::{
- builtin_fn_macro::BuiltinFnLikeExpander,
mod_path::path,
- name,
- name::{AsName, Name},
HirFileId, InFile, InMacroFile, MacroFileId, MacroFileIdExt,
+ {
+ name,
+ name::{AsName, Name},
+ },
};
use hir_ty::{
diagnostics::{
@@ -822,8 +823,10 @@ impl SourceAnalyzer {
macro_call: InFile<&ast::MacroCall>,
) -> Option<MacroFileId> {
let krate = self.resolver.krate();
+ // FIXME: This causes us to parse, generally this is the wrong approach for resolving a
+ // macro call to a macro call id!
let macro_call_id = macro_call.as_call_id(db.upcast(), krate, |path| {
- self.resolver.resolve_path_as_macro_def(db.upcast(), &path, Some(MacroSubNs::Bang))
+ self.resolver.resolve_path_as_macro_def(db.upcast(), path, Some(MacroSubNs::Bang))
})?;
// why the 64?
Some(macro_call_id.as_macro_file()).filter(|it| it.expansion_level(db.upcast()) < 64)
@@ -839,37 +842,13 @@ impl SourceAnalyzer {
infer.variant_resolution_for_expr(expr_id)
}
- pub(crate) fn is_unsafe_macro_call(
+ pub(crate) fn is_unsafe_macro_call_expr(
&self,
db: &dyn HirDatabase,
- macro_call: InFile<&ast::MacroCall>,
+ macro_expr: InFile<&ast::MacroExpr>,
) -> bool {
- // check for asm/global_asm
- if let Some(mac) = self.resolve_macro_call(db, macro_call) {
- let ex = match mac.id {
- hir_def::MacroId::Macro2Id(it) => it.lookup(db.upcast()).expander,
- hir_def::MacroId::MacroRulesId(it) => it.lookup(db.upcast()).expander,
- _ => hir_def::MacroExpander::Declarative,
- };
- match ex {
- hir_def::MacroExpander::BuiltIn(e)
- if e == BuiltinFnLikeExpander::Asm || e == BuiltinFnLikeExpander::GlobalAsm =>
- {
- return true
- }
- _ => (),
- }
- }
- let macro_expr = match macro_call
- .map(|it| it.syntax().parent().and_then(ast::MacroExpr::cast))
- .transpose()
- {
- Some(it) => it,
- None => return false,
- };
-
if let (Some((def, body, sm)), Some(infer)) = (&self.def, &self.infer) {
- if let Some(expanded_expr) = sm.macro_expansion_expr(macro_expr.as_ref()) {
+ if let Some(expanded_expr) = sm.macro_expansion_expr(macro_expr) {
let mut is_unsafe = false;
unsafe_expressions(
db,