Files
rust/src/libsyntax/ext/log_syntax.rs
T
Huon Wilson cda33346d0 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 `()`.
2014-03-22 01:27:23 +11:00

28 lines
961 B
Rust

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use ast;
use codemap;
use ext::base;
use print;
pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
sp: codemap::Span,
tt: &[ast::TokenTree])
-> base::MacResult {
cx.print_backtrace();
println!("{}", print::pprust::tt_to_str(&ast::TTDelim(
@tt.iter().map(|x| (*x).clone()).collect())));
// any so that `log_syntax` can be invoked as an expression and item.
base::MacResult::dummy_any(sp)
}