mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
hir/semantics: Only allow expansion of specific built in macros
This commit is contained in:
parent
4af21ffb02
commit
5d5f68af3f
1 changed files with 30 additions and 2 deletions
|
@ -19,8 +19,12 @@ use hir_def::{
|
||||||
AsMacroCall, DefWithBodyId, FunctionId, MacroId, TraitId, VariantId,
|
AsMacroCall, DefWithBodyId, FunctionId, MacroId, TraitId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
attrs::collect_attrs, db::ExpandDatabase, files::InRealFile, name::AsName, InMacroFile,
|
attrs::collect_attrs,
|
||||||
MacroCallId, MacroFileId, MacroFileIdExt,
|
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
|
||||||
|
db::ExpandDatabase,
|
||||||
|
files::InRealFile,
|
||||||
|
name::AsName,
|
||||||
|
InMacroFile, MacroCallId, MacroFileId, MacroFileIdExt,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
@ -319,6 +323,30 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
} else {
|
} else {
|
||||||
sa.expand(self.db, macro_call)?
|
sa.expand(self.db, macro_call)?
|
||||||
};
|
};
|
||||||
|
let macro_call = self.db.lookup_intern_macro_call(file_id.macro_call_id);
|
||||||
|
|
||||||
|
match macro_call.def.kind {
|
||||||
|
hir_expand::MacroDefKind::BuiltIn(
|
||||||
|
_,
|
||||||
|
BuiltinFnLikeExpander::Cfg
|
||||||
|
| BuiltinFnLikeExpander::StdPanic
|
||||||
|
| BuiltinFnLikeExpander::Stringify
|
||||||
|
| BuiltinFnLikeExpander::CorePanic,
|
||||||
|
)
|
||||||
|
| hir_expand::MacroDefKind::BuiltInEager(
|
||||||
|
_,
|
||||||
|
EagerExpander::Env
|
||||||
|
| EagerExpander::Concat
|
||||||
|
| EagerExpander::Include
|
||||||
|
| EagerExpander::OptionEnv
|
||||||
|
| EagerExpander::IncludeStr
|
||||||
|
| EagerExpander::ConcatBytes
|
||||||
|
| EagerExpander::IncludeBytes,
|
||||||
|
) => {
|
||||||
|
// Do nothing and allow matching macros to be expanded
|
||||||
|
}
|
||||||
|
_ => return None,
|
||||||
|
}
|
||||||
|
|
||||||
let node = self.parse_or_expand(file_id.into());
|
let node = self.parse_or_expand(file_id.into());
|
||||||
Some(node)
|
Some(node)
|
||||||
|
|
Loading…
Reference in a new issue