我有一个涉及宏的编译错误:
<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不幸的是,宏是递归的,所以很难弄清楚编译器在抱怨什么,而且似乎行号是针对扩展的宏而不是我的代码。
如何查看展开的宏?有没有一个我可以传递给rustc (或者更好的是cargo)的标志来把它转储出去?
(这个宏来自rust-mdo,尽管我认为它无关紧要。)
发布于 2016-06-05 14:10:55
cargo rustc --profile=check -- -Zunpretty=expanded,但更简洁的替代方案是cargo-expand机箱。它提供了一个Cargo子命令cargo expand,用于打印宏展开的结果。它还通过rustfmt传递扩展的代码,这通常会产生比rustc的默认输出更具可读性的代码。
通过运行cargo install cargo-expand进行安装。
发布于 2015-02-18 17:53:44
可以,您可以将一个名为--pretty=expanded的特殊标志传递给rustc
% 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 ()
{
()
=>
[],
}));
}但是,您需要首先通过传递-Z unstable-options来允许它。
从Rust 1.1开始,您可以将这些参数传递给Cargo,如下所示:
cargo rustc -- -Z unstable-options --pretty=expanded发布于 2021-08-19 07:01:29
从nightly-2021-07-28开始,必须传递-Zunpretty=expanded而不是-Zunstable-options --pretty=expanded,如下所示:
% rustc -Zunpretty=expanded test.rs或者:
% cargo rustc -- -Zunpretty=expanded相关的rustc提交
已通过this commit从nightly-2021-07-28中删除了--pretty参数。对-Zunpretty=expanded的支持是通过this commit添加到nightly-2018-01-24的。
https://stackoverflow.com/questions/28580386
复制相似问题