不能在 `cargo` 中使用 `-Z macro-backtrace` 不稳定选项

Din*_*cio 18 nightly-build rust rust-cargo rustup

我正在编写 rust 宏,但遇到了有关我无法理解的宏的错误。为了更好地理解它,我尝试通过设置-Z macro-backtrace不稳定选项并再次编译来遵循编译器的建议。这是说的建议:

note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Run Code Online (Sandbox Code Playgroud)

但是这样做:

cargo run -Z macro-backtrace
Run Code Online (Sandbox Code Playgroud)

结果如下:

error: unknown `-Z` flag specified: macro-backtrace
Run Code Online (Sandbox Code Playgroud)

我已经通过rustup override nightly在项目目录中运行并rustup default nightly为将来使用此功能而完全切换到夜间工具链,但错误仍然存​​在。

在通过网络挖掘时,我找到了一种列出所有-Z选项的方法cargo -Z help


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.
Run Code Online (Sandbox Code Playgroud)

-Z macro-backtrace......我去了指定的链接,但即使在那里搜索也macro-backtrace没有结果。

所以我被卡住了......我很想使用这个功能,但似乎找不到激活它的方法。

任何帮助将不胜感激。

Sve*_*ach 31

-Z macro-backtracerustc一面旗帜,而不是cargo一面旗帜。您应该能够将其传递给rustcusing cargo +nightly rustc -- -Z macro-backtrace。(+nightly如果您已经切换到夜间编译器作为默认设置,则命令行中的 是可选的。)

或者,您可以设置RUSTFLAGS环境变量:

export RUSTFLAGS="-Z macro-backtrace"
Run Code Online (Sandbox Code Playgroud)

  • 我建议像这样使用它:`RUSTFLAGS =“-Z macro-backtrace”cargo ...`但是,它不会污染环境。变量 (14认同)
  • 非常有效,谢谢。如果错误消息提到这一点那就太好了...... (9认同)