auto merge of #12998 : huonw/rust/log_syntax, r=alexcrichton
syntax: allow `trace_macros!` and `log_syntax!` in item position.
Previously
trace_macros!(true)
fn main() {}
would complain about `trace_macros` being an expression macro in item
position. This is a pointless limitation, because the macro is purely
compile-time, with no runtime effect. (And similarly for log_syntax.)
This also changes the behaviour of `trace_macros!` very slightly, it
used to be equivalent to
macro_rules! trace_macros {
(true $($_x: tt)*) => { true };
(false $($_x: tt)*) => { false }
}
I.e. you could invoke it with arbitrary trailing arguments, which were
ignored. It is changed to accept only exactly `true` or `false` (with no
trailing arguments) and expands to `()`.
This commit is contained in:
@@ -119,13 +119,31 @@ impl MacResult {
|
||||
pub fn raw_dummy_expr(sp: codemap::Span) -> @ast::Expr {
|
||||
@ast::Expr {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: ast::ExprTup(Vec::new()),
|
||||
span: sp
|
||||
node: ast::ExprLit(@codemap::respan(sp, ast::LitNil)),
|
||||
span: sp,
|
||||
}
|
||||
}
|
||||
pub fn dummy_expr(sp: codemap::Span) -> MacResult {
|
||||
MRExpr(MacResult::raw_dummy_expr(sp))
|
||||
}
|
||||
pub fn dummy_any(sp: codemap::Span) -> MacResult {
|
||||
MRAny(~DummyMacResult { sp: sp })
|
||||
}
|
||||
}
|
||||
struct DummyMacResult {
|
||||
sp: codemap::Span
|
||||
}
|
||||
impl AnyMacro for DummyMacResult {
|
||||
fn make_expr(&self) -> @ast::Expr {
|
||||
MacResult::raw_dummy_expr(self.sp)
|
||||
}
|
||||
fn make_items(&self) -> SmallVector<@ast::Item> {
|
||||
SmallVector::zero()
|
||||
}
|
||||
fn make_stmt(&self) -> @ast::Stmt {
|
||||
@codemap::respan(self.sp,
|
||||
ast::StmtExpr(MacResult::raw_dummy_expr(self.sp), ast::DUMMY_NODE_ID))
|
||||
}
|
||||
}
|
||||
|
||||
/// An enum representing the different kinds of syntax extensions.
|
||||
|
||||
Reference in New Issue
Block a user