如何查看扩展的Rust宏的代码输出?
例如,我有一个片段:
macro_rules! five_times {
($x:expr) => (5 * $x);
}
fn main() {
let a = five_times!(2 + 3);
}我想看到这样的事情:
fn main() {
let a = 5 * (2 + 3);
}发布于 2018-04-05 08:58:02
在使用夜间Rust时,可以对源文件使用以下命令:
rustc --pretty expanded -Z unstable-options FILENAME.rs这将打印以下输出:
macro_rules! five_times(( $ x : expr ) => ( 5 * $ x ) ;);
fn main() { let a = 5 * (2 + 3); }更新
对于2021年版本,命令更改为(感谢@ to 54321):
rustc -Zunpretty=expanded FILENAME.rshttps://stackoverflow.com/questions/49668183
复制相似问题