Check attributes in expand_mac_invoc
This commit is contained in:
parent
f4075e9467
commit
215c1460f6
@ -16,7 +16,7 @@ use ast;
|
||||
use ext::mtwt;
|
||||
use ext::build::AstBuilder;
|
||||
use attr;
|
||||
use attr::{AttrMetaMethods, WithAttrs};
|
||||
use attr::{AttrMetaMethods, WithAttrs, ThinAttributesExt};
|
||||
use codemap;
|
||||
use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
|
||||
use ext::base::*;
|
||||
@ -86,14 +86,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
|
||||
// expr_mac should really be expr_ext or something; it's the
|
||||
// entry-point for all syntax extensions.
|
||||
ast::ExprKind::Mac(mac) => {
|
||||
if let Some(ref attrs) = attrs {
|
||||
check_attributes(attrs, fld);
|
||||
}
|
||||
|
||||
// Assert that we drop any macro attributes on the floor here
|
||||
drop(attrs);
|
||||
|
||||
expand_mac_invoc(mac, span, fld)
|
||||
expand_mac_invoc(mac, attrs.into_attr_vec(), span, fld)
|
||||
}
|
||||
|
||||
ast::ExprKind::InPlace(placer, value_expr) => {
|
||||
@ -204,7 +197,12 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
|
||||
}
|
||||
|
||||
/// Expand a (not-ident-style) macro invocation. Returns the result of expansion.
|
||||
fn expand_mac_invoc<T: MacroGenerable>(mac: ast::Mac, span: Span, fld: &mut MacroExpander) -> T {
|
||||
fn expand_mac_invoc<T>(mac: ast::Mac, attrs: Vec<ast::Attribute>, span: Span,
|
||||
fld: &mut MacroExpander) -> T
|
||||
where T: MacroGenerable,
|
||||
{
|
||||
check_attributes(&attrs, fld);
|
||||
|
||||
// it would almost certainly be cleaner to pass the whole
|
||||
// macro invocation in, rather than pulling it apart and
|
||||
// marking the tts and the ctxt separately. This also goes
|
||||
@ -527,15 +525,8 @@ fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
|
||||
_ => return expand_non_macro_stmt(stmt, fld)
|
||||
};
|
||||
|
||||
if let Some(ref attrs) = attrs {
|
||||
check_attributes(attrs, fld);
|
||||
}
|
||||
|
||||
// Assert that we drop any macro attributes on the floor here
|
||||
drop(attrs);
|
||||
|
||||
let mut fully_expanded: SmallVector<ast::Stmt> =
|
||||
expand_mac_invoc(mac.unwrap(), stmt.span, fld);
|
||||
expand_mac_invoc(mac.unwrap(), attrs.into_attr_vec(), stmt.span, fld);
|
||||
|
||||
// If this is a macro invocation with a semicolon, then apply that
|
||||
// semicolon to the final statement produced by expansion.
|
||||
@ -752,7 +743,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
|
||||
}
|
||||
p.and_then(|ast::Pat {node, span, ..}| {
|
||||
match node {
|
||||
PatKind::Mac(mac) => expand_mac_invoc(mac, span, fld),
|
||||
PatKind::Mac(mac) => expand_mac_invoc(mac, Vec::new(), span, fld),
|
||||
_ => unreachable!()
|
||||
}
|
||||
})
|
||||
@ -1007,8 +998,7 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
|
||||
span: fld.new_span(ii.span)
|
||||
}),
|
||||
ast::ImplItemKind::Macro(mac) => {
|
||||
check_attributes(&ii.attrs, fld);
|
||||
expand_mac_invoc(mac, ii.span, fld)
|
||||
expand_mac_invoc(mac, ii.attrs, ii.span, fld)
|
||||
}
|
||||
_ => fold::noop_fold_impl_item(ii, fld)
|
||||
}
|
||||
@ -1052,7 +1042,7 @@ pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
|
||||
let t = match t.node.clone() {
|
||||
ast::TyKind::Mac(mac) => {
|
||||
if fld.cx.ecfg.features.unwrap().type_macros {
|
||||
expand_mac_invoc(mac, t.span, fld)
|
||||
expand_mac_invoc(mac, Vec::new(), t.span, fld)
|
||||
} else {
|
||||
feature_gate::emit_feature_err(
|
||||
&fld.cx.parse_sess.span_diagnostic,
|
||||
|
Loading…
x
Reference in New Issue
Block a user