58

I'm trying to run my tests with nightly Rust using Windows Powershell. I run cargo test in the directory, and I get

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)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Obviously, I have to tell Cargo to compile it on the nightly channel, but how? I can't find any reference to specifying a channel in the help section, or any website I've found.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Phoenix
  • 1,553
  • 2
  • 13
  • 29

2 Answers2

109

The command line solution may help you to configure your IDE:

cargo +nightly test

Provided, of course, that you have the nightly channel installed. If not, perhaps install it with rustup install nightly (no need to switch to it, but check you're still on stable: rustup show).

  • 4
    In case anyone ran into the same thing I did, the order of arguments matters. That is, `cargo test +nightly` does not work. – firechant Feb 23 '18 at 15:03
48

The +<toolchain> functionality comes from rustup, the Rust toolchain manager. It works for both cargo +<toolchain> as well as rustc +<toolchain>.

In addition, you can

  • Use rustup run <toolchain> <any arbitrary command goes here>
  • Change into the directory and run rustup override set <toolchain> to always use the nightly toolchain in that directory, since your project requires nightly features.
  • Create a file called rust-toolchain.toml in your directory containing
    [toolchain]
    channel = "nightly"
    
    (previously rust-toolchain just containing the name of the toolchain required (e.g. nightly)). This has the safe effect as an override like above, but can be committed to source control.

See also:

cafce25
  • 15,907
  • 4
  • 25
  • 31
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366