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:
@@ -835,7 +835,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
None => self.get_macro(res).map(|macro_data| Arc::clone(¯o_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(¯o_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(
|
||||
|
||||
Reference in New Issue
Block a user