mbe: Handle applying attribute rules with paths

Add infrastructure to apply an attribute macro given argument tokens and
body tokens.

Teach the resolver to consider `macro_rules` macros when looking for an
attribute via a path.

This does not yet handle local `macro_rules` attributes.
This commit is contained in:
Josh Triplett
2025-07-11 01:40:12 -07:00
parent 0cc0b11cce
commit 34be8abb70
4 changed files with 185 additions and 28 deletions

View File

@@ -835,7 +835,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
_ => None,
},
None => self.get_macro(res).map(|macro_data| Arc::clone(&macro_data.ext)),
None => self.get_macro(res).map(|macro_data| match kind {
Some(MacroKind::Attr) if let Some(ref ext) = macro_data.attr_ext => Arc::clone(ext),
_ => Arc::clone(&macro_data.ext),
}),
};
Ok((ext, res))
}
@@ -1168,7 +1171,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
node_id: NodeId,
edition: Edition,
) -> MacroData {
let (mut ext, mut nrules) = compile_declarative_macro(
let (mut ext, mut attr_ext, mut nrules) = compile_declarative_macro(
self.tcx.sess,
self.tcx.features(),
macro_def,
@@ -1185,13 +1188,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// The macro is a built-in, replace its expander function
// while still taking everything else from the source code.
ext.kind = builtin_ext_kind.clone();
attr_ext = None;
nrules = 0;
} else {
self.dcx().emit_err(errors::CannotFindBuiltinMacroWithName { span, ident });
}
}
MacroData { ext: Arc::new(ext), nrules, macro_rules: macro_def.macro_rules }
MacroData { ext: Arc::new(ext), attr_ext, nrules, macro_rules: macro_def.macro_rules }
}
fn path_accessible(