Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do macros not expand interpolated token trees?

Tags:

rust

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
like image 595
user Avatar asked May 30 '15 12:05

user


1 Answers

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.

like image 136
bluss Avatar answered Nov 12 '22 15:11

bluss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!