From cda33346d0e9e4d1ff26163583831f96d42a4bc0 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 18 Mar 2014 23:14:08 +1100 Subject: 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 `()`. --- src/libsyntax/ext/log_syntax.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/libsyntax/ext/log_syntax.rs') diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index b94928238e9..1ce08b8303e 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -10,11 +10,10 @@ use ast; use codemap; -use ext::base::*; use ext::base; use print; -pub fn expand_syntax_ext(cx: &mut ExtCtxt, +pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tt: &[ast::TokenTree]) -> base::MacResult { @@ -23,13 +22,6 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, println!("{}", print::pprust::tt_to_str(&ast::TTDelim( @tt.iter().map(|x| (*x).clone()).collect()))); - //trivial expression - MRExpr(@ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprLit(@codemap::Spanned { - node: ast::LitNil, - span: sp - }), - span: sp, - }) + // any so that `log_syntax` can be invoked as an expression and item. + base::MacResult::dummy_any(sp) } -- cgit 1.4.1-3-g733a5