如何使用夜间频道执行cargo test?

62

我正在尝试使用Windows Powershell使用nightly Rust运行我的测试。我在目录中运行cargo test,然后我得到了以下提示:

Compiling rustcraft v0.1.0 (file:///C:/Users/Phoenix/Desktop/Rust/rustcraft)
error[E0554]: #![feature] may not be used on the stable release channel
 --> C:\Users\Phoenix\Desktop\Rust\rustcraft\src\main.rs:1:1
  |
1 | #![feature(integer_atomics)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
 --> C:\Users\Phoenix\Desktop\Rust\rustcraft\src\main.rs:2:1
  |
2 | #![feature(collections)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^

显然,我必须告诉Cargo在nightly频道上进行编译,但如何操作呢?在帮助部分或我找到的任何网站中,都找不到有关指定频道的参考资料。

2个回答

114

命令行解决方案可以帮助您配置您的IDE:

cargo +nightly test

当然,前提是您已经安装了夜间频道。如果没有,请使用 rustup install nightly 进行安装(无需切换到它,但请确保您仍在稳定通道上: rustup show)。

4
如果有人遇到和我一样的问题,需要注意参数的顺序。也就是说,“cargo test +nightly”是行不通的。 - firechant

51

+<toolchain> 功能来自于 Rust 工具链管理器 rustup。它可同时适用于 cargo +<toolchain>rustc +<toolchain>

此外,您还可以

  • 使用 rustup run <toolchain> <任意命令>
  • 进入目录并运行 rustup override set <toolchain>,以便始终在该目录中使用夜间工具链,因为您的项目需要夜间功能。
  • 在您的目录中创建一个名为rust-toolchain.toml的文件,其中包含
    [toolchain]
    channel = "nightly"
    
    (之前只包含所需工具链的名称(例如 nightly)的rust-toolchain)。这与上面的override具有相同的安全效果,但可以提交到源代码控制。

另请参见:


2
一个例子:rustup run nightly cargo build --target wasm32-unknown-unknown - STEEL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接