rust error[E0554]: `#![feature]` may not be used on the stable release channel (switch nightly version)

created at 08-23-2021 views: 2

description

From the error message #![feature] may not be used on the stable release channel, it can be seen that the channel currently used for compilation does not contain the #![feature] function. What should I do? Change the channel!
Is it necessary to understand what Channel refers to before changing? What channels are available? To put it simply, channel means that the Rust development environment we use is a stable version, a trial version, or an early adopter version? Just like we usually develop software, adding new functions to the software cannot directly replace the online stable version of the software, because the new version may have bugs and need to be tried for a while, try for a while to confirm that there is no problem, and then replace the original Stable version. The stable version, the trial version, and the early adopter version correspond to stable, beta, nightly. The functions that are not in stable may be available in beta and nightly. To use the beta and nightly version, first check whether it is installed:

$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)

It can be seen that when only the stable version is installed in the current environment, for other channels, take the installation of nightly as an example:

$ rustup toolchain install nightly

You can also specify specific version information during installation, and install the latest version by default.

Usage

Method 1

The simpler way is to install directly and change the default channel of the current system

$ rustup default nightly

In this way, even the above installation steps are done together, and the cargo build is executed directly to use the nightly channel to compile and build the project. That is, the original stable project is now changed to nightly. Maybe we don’t want to change it all. What to do? Can it be used only temporarily, yes:

Method 2

Use rustup run to specify the channel

$ rustup run nightly cargo build

It’s okay to write this once temporarily. If you use a lot of cargo build, you always have to type a string in front of it. It will inevitably be troublesome. Can the current project default to nightly without affecting other projects? It’s also possible.

Method 3

Use rustup overwrite to set the channel used by the current project

Enter the project directory to execute:

$ rustup override set nightly

If you execute cargo build again, no error will be reported.

Problem solved.

created at:08-23-2021
edited at: 08-23-2021: