我有一个涉及宏的编译错误:
<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
Run Code Online (Sandbox Code Playgroud)
不幸的是,宏是递归的,因此很难弄清楚编译器在抱怨什么,而且看起来线号是针对扩展宏而不是我的代码.
我怎样才能看到扩展的宏?是否有一面旗帜可以传递给rustc(甚至更好的货物)来解决这个问题?
(这个宏来自rust-mdo,虽然我认为不重要.)
dto*_*nay 51
更简洁的替代方案cargo rustc -- -Zunstable-options --pretty=expanded是货物扩张板条箱.它提供了一个Cargo子命令cargo expand,用于打印宏扩展的结果.它还传递了扩展代码,通过rustfmt该代码通常会产生比rustc的默认输出更易读的代码.
通过运行安装cargo install cargo-expand.
Vla*_*eev 48
是的,您可以传递一个特殊标志rustc,称为--pretty=expanded:
% cat test.rs
fn main() {
println!("Hello world");
}
% rustc -Z unstable-options --pretty=expanded test.rs
#![feature(no_std)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate "std" as std;
fn main() {
::std::old_io::stdio::println_args(::std::fmt::Arguments::new_v1({
static __STATIC_FMTSTR:
&'static [&'static str]
=
&["Hello world"];
__STATIC_FMTSTR
},
&match ()
{
()
=>
[],
}));
}
Run Code Online (Sandbox Code Playgroud)
但是,你需要首先允许它通过-Z unstable-options.
从Rust 1.1开始,您可以将这些参数传递给Cargo,如下所示:
cargo rustc -- -Z unstable-options --pretty=expanded
Run Code Online (Sandbox Code Playgroud)
Ens*_*lic 16
从 开始nightly-2021-07-28,必须通过-Zunpretty=expanded而不是-Zunstable-options --pretty=expanded,如下所示:
% rustc -Zunpretty=expanded test.rs
Run Code Online (Sandbox Code Playgroud)
或者:
% cargo rustc -- -Zunpretty=expanded
Run Code Online (Sandbox Code Playgroud)
该参数已通过此提交--pretty删除。通过此提交添加了对的支持。nightly-2021-07-28-Zunpretty=expandednightly-2018-01-24