5

Why does this:

macro_rules! a_macro {
    ($($a:tt)+) => ($($a)+);
}   

fn main() {
    let x:u32 = 1;
    let y:u32 = a_macro!(-x);
}

fail to compile with

<anon>:2:23: 2:25 error: unexpected token: `an interpolated tt`
<anon>:2     ($($a:tt)+) => ($($a)+);
                               ^~
playpen: application terminated with error code 101
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user
  • 4,920
  • 3
  • 25
  • 38

1 Answers1

5

The why is: it's not implemented yet. This is a known limitation (as of Rust 1.0). tt arguments to macros are useful, but they must always be forwarded to macros when used.

Community
  • 1
  • 1
bluss
  • 12,472
  • 1
  • 49
  • 48
  • This saddens me. I was hoping to make combinators with macros, and being unable to return tokens makes that painful. :-( – user May 31 '15 at 01:10
  • @user: macros are very much a work in progress at the moment; already incredibly useful, but nowhere near as flexible as they could be. – Matthieu M. May 31 '15 at 15:02
  • @MatthieuM. Not complaining about their limitations so much as wishing I could re-order chronology to use the spectacular Rust of the future. :-D – user Jun 01 '15 at 04:32
  • Rest assured macros are already [insane (nightly branch)](https://play.rust-lang.org/?gist=7667b480a0835bd8740a&version=nightly) – bluss Jun 01 '15 at 12:29