Merge #6030
6030: Small proc macro cleanup r=jonas-schievink a=jonas-schievink git got really confused, but all I did in the first commit was unindent a few lines Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
commit
5e1500ec74
@ -908,12 +908,12 @@ pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
|
||||
/// Indicate it is a proc-macro
|
||||
pub fn is_proc_macro(&self) -> bool {
|
||||
matches!(self.id.kind, MacroDefKind::CustomDerive(_))
|
||||
matches!(self.id.kind, MacroDefKind::ProcMacro(_))
|
||||
}
|
||||
|
||||
/// Indicate it is a derive macro
|
||||
pub fn is_derive_macro(&self) -> bool {
|
||||
matches!(self.id.kind, MacroDefKind::CustomDerive(_) | MacroDefKind::BuiltInDerive(_))
|
||||
matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ fn collect_proc_macro(&mut self) {
|
||||
let macro_id = MacroDefId {
|
||||
ast_id: None,
|
||||
krate: Some(krate),
|
||||
kind: MacroDefKind::CustomDerive(expander),
|
||||
kind: MacroDefKind::ProcMacro(expander),
|
||||
local_inner: false,
|
||||
};
|
||||
|
||||
@ -874,7 +874,9 @@ fn collect(&mut self, items: &[ModItem]) {
|
||||
|
||||
for &item in items {
|
||||
let attrs = self.item_tree.attrs(item.into());
|
||||
if self.is_cfg_enabled(attrs) {
|
||||
if !self.is_cfg_enabled(attrs) {
|
||||
continue;
|
||||
}
|
||||
let module =
|
||||
ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
|
||||
let container = ContainerId::ModuleId(module);
|
||||
@ -911,9 +913,7 @@ fn collect(&mut self, items: &[ModItem]) {
|
||||
let container = ContainerId::ModuleId(module);
|
||||
let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) }
|
||||
.intern(self.def_collector.db);
|
||||
self.def_collector.def_map.modules[self.module_id]
|
||||
.scope
|
||||
.define_impl(impl_id)
|
||||
self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id)
|
||||
}
|
||||
ModItem::Function(id) => {
|
||||
let func = &self.item_tree[id];
|
||||
@ -1054,7 +1054,6 @@ fn collect(&mut self, items: &[ModItem]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_module(&mut self, module: &Mod, attrs: &Attrs) {
|
||||
let path_attr = attrs.by_key("path").string_value();
|
||||
|
@ -143,7 +143,7 @@ pub(crate) fn macro_def(
|
||||
Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default())))
|
||||
}
|
||||
MacroDefKind::BuiltInEager(_) => None,
|
||||
MacroDefKind::CustomDerive(expander) => {
|
||||
MacroDefKind::ProcMacro(expander) => {
|
||||
Some(Arc::new((TokenExpander::ProcMacro(expander), mbe::TokenMap::default())))
|
||||
}
|
||||
}
|
||||
@ -249,7 +249,7 @@ pub(crate) fn expand_proc_macro(
|
||||
};
|
||||
|
||||
let expander = match loc.def.kind {
|
||||
MacroDefKind::CustomDerive(expander) => expander,
|
||||
MacroDefKind::ProcMacro(expander) => expander,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -129,7 +129,7 @@ fn eager_macro_recur(
|
||||
MacroDefKind::Declarative
|
||||
| MacroDefKind::BuiltIn(_)
|
||||
| MacroDefKind::BuiltInDerive(_)
|
||||
| MacroDefKind::CustomDerive(_) => {
|
||||
| MacroDefKind::ProcMacro(_) => {
|
||||
let expanded = lazy_expand(db, &def, curr.with_value(child.clone()), krate)?;
|
||||
// replace macro inside
|
||||
eager_macro_recur(db, expanded, krate, macro_resolver)?
|
||||
|
@ -33,7 +33,7 @@ pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene {
|
||||
MacroDefKind::BuiltIn(_) => (None, false),
|
||||
MacroDefKind::BuiltInDerive(_) => (None, false),
|
||||
MacroDefKind::BuiltInEager(_) => (None, false),
|
||||
MacroDefKind::CustomDerive(_) => (None, false),
|
||||
MacroDefKind::ProcMacro(_) => (None, false),
|
||||
}
|
||||
}
|
||||
MacroCallId::EagerMacro(_id) => (None, false),
|
||||
|
@ -246,7 +246,7 @@ pub enum MacroDefKind {
|
||||
// FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
|
||||
BuiltInDerive(BuiltinDeriveExpander),
|
||||
BuiltInEager(EagerExpander),
|
||||
CustomDerive(ProcMacroExpander),
|
||||
ProcMacro(ProcMacroExpander),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
Loading…
Reference in New Issue
Block a user