如何查看导致我的编译错误的扩展宏代码? [英] How do I see the expanded macro code that's causing my compile error?
问题描述
我遇到一个涉及宏的编译错误:
I have a compile error involving a macro:
<mdo macros>:6:19: 6:50 error: cannot move out of captured outer variable in an `FnMut` closure
<mdo macros>:6 bind ( $ e , move | $ p | mdo ! { $ ( $ t ) * } ) ) ; (
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<mdo macros>:1:1: 14:36 note: in expansion of mdo!
<mdo macros>:6:27: 6:50 note: expansion site
<mdo macros>:1:1: 14:36 note: in expansion of mdo!
<mdo macros>:6:27: 6:50 note: expansion site
<mdo macros>:1:1: 14:36 note: in expansion of mdo!
src/parser.rs:30:42: 37:11 note: expansion site
error: aborting due to previous error
不幸的是,该宏是递归的,因此很难弄清编译器在抱怨什么,加上行号似乎是扩展宏而不是我的代码.
Unfortunately, the macro is recursive so it's hard to figure out what the compiler is complaining about, plus it seems like the line numbers are for the expanded macro rather than my code.
如何查看展开的宏?有没有我可以传递给rustc(甚至更好的货物)的标志,以将其倾倒出去?
How can I see the expanded macro? Is there a flag I can pass to rustc (or even better, cargo) to dump this out?
(此宏来自 rust-mdo ,尽管我认为这并不重要.)
(This macro is from rust-mdo, though I don't think it matters.)
推荐答案
货物rustc--Zunstable-options --pretty = expanded
,但是更简洁的替代方法是 rustfmt
传递扩展的代码,通常会产生更多结果可读代码,而不是rustc的默认输出.
cargo rustc -- -Zunstable-options --pretty=expanded
, but a more concise alternative is the cargo-expand crate. It provides a Cargo subcommand cargo expand
which prints the result of macro expansion. It also passes the expanded code through rustfmt
which generally results in much more readable code than the default output from rustc.
通过运行 cargo install cargo-expand
进行安装.
这篇关于如何查看导致我的编译错误的扩展宏代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!