gpt4 book ai didi

debugging - 如何查看导致我的编译错误的扩展宏代码?

转载 作者:行者123 更新时间:2023-12-03 11:46:30 26 4
gpt4 key购买 nike

我有一个涉及宏的编译错误:

<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,尽管我认为这并不重要。)

最佳答案

cargo rustc -- -Zunstable-options --pretty=expanded,但更简洁的替代方法是cargo-expand条板箱。它提供了一个Cargo子命令cargo expand,可打印宏扩展的结果。它还通过 rustfmt 传递扩展的代码,该代码通常比rustc的默认输出可读得多的代码。
通过运行cargo install cargo-expand进行安装。

关于debugging - 如何查看导致我的编译错误的扩展宏代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66426131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com