我正在编写 Rust 宏,但遇到了一个我无法理解的宏错误。为了更好地理解它,我尝试按照编译器的建议设置 -Z macro-backtrace
不稳定选项,并重新编译。这是建议内容:
note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
但是做这个:
cargo run -Z macro-backtrace
导致此结果:
error: unknown `-Z` flag specified: macro-backtrace
我已经通过在项目目录中运行 rustup override nightly
和未来使用此功能时运行 rustup default nightly
来完全切换到夜间工具链,但错误仍然存在。
在搜索网络时,我发现了一种使用 cargo -Z help
列出所有 -Z
选项的方法:
Available unstable (nightly-only) flags:
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
-Z minimal-versions -- Install minimal dependency versions instead of maximum
-Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
-Z unstable-options -- Allow the usage of unstable options
-Z timings -- Display concurrency information
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
-Z terminal-width -- Provide a terminal width to rustc for error truncation
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information about these flags.
没有 -Z macro-backtrace
这个宏回溯...我访问了指定的链接,但即使在那里搜索 macro-backtrace
也没有结果。
所以我被卡住了...我非常想使用这个功能,但似乎找不到激活它的方法。
任何帮助将不胜感激。
RUSTFLAGS="-Z macro-backtrace" cargo ...
,但它不会污染环境变量。 - Xiaojiba