【问题标题】:Do macros not expand interpolated token trees?宏不扩展插值标记树吗?
【发布时间】:2015-05-30 12:26:58
【问题描述】:

为什么this:

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

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

编译失败

<anon>:2:23: 2:25 error: unexpected token: `an interpolated tt`
<anon>:2     ($($a:tt)+) => ($($a)+);
                               ^~
playpen: application terminated with error code 101

【问题讨论】:

    标签: rust


    【解决方案1】:

    原因是:它还没有实现。这是一个已知的限制(从 Rust 1.0 开始)。 ttare useful 的参数,但在使用时必须始终将它们转发给宏。

    【讨论】:

    • 这让我很伤心。我希望用宏来制作组合器,而无法返回令牌会让这很痛苦。 :-(
    • @user:宏目前在很大程度上是一项正在进行的工作;已经非常有用,但远没有它们可以的灵活。
    • @MatthieuM。与其抱怨它们的局限性,不如说希望我可以重新排序年表以使用未来壮观的 Rust。 :-D
    • 放心宏已经insane (nightly branch)
    猜你喜欢
    • 2014-04-17
    • 1970-01-01
    • 2014-02-24
    • 2012-01-22
    • 2017-03-28
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多