#![feature]` may not be used on the stable release channel 问题解决及设置Rust Channel的三种方式

 今天在编译一个Rust开源项目时报了下面的错误:

 Compiling base_proc_macro v0.1.0 (/data/code/rust/tensorbase/crates/base/proc_macro)
error[E0554]: `#![feature]` may not be used on the stable release channel
  --> crates/base/proc_macro/src/lib.rs:17:1
   |
17 | #![feature(proc_macro_diagnostic)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
  --> crates/base/proc_macro/src/lib.rs:18:1
   |
18 | #![feature(proc_macro_span)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

从错误信息`#![feature]` may not be used on the stable release channel可以看出当前编译使用的channel还没有包含#![feature]功能,那咋办呢?换channel呗!换之前是不是要先了解下Channel指的是啥?都有哪些可用的Channel? 简单来说channel就是代表我们使用的Rust开发环境是稳定版的,还是试用版的,还是尝鲜版的?就像我们平常开发软件一样一样的,在软件里添加了新功能不能直接把线上的稳定版软件替换掉,因为新版本可能还有bug需要试用一段,试用一段确认没问题了再替换原来的稳定版。稳定版试用版尝鲜版分别对应stable,beta,nightly.在stable里没有的功能,可能在beta和nightly里就有了。要使用beta和nightly版首先要看下有没有安装:

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

可以看当当前环境只安装了稳定(stable)版,接下来其它Channel,以安装nightly为例:

$ rustup toolchain install nightly
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
695.5 KiB / 695.5 KiB (100 %)  40.2 KiB/s in 34s ETA:  0s
info: latest update on 2021-01-26, rust version 1.51.0-nightly (f4eb5d9f7 2021-01-25)
info: downloading component 'cargo'
info: retrying download for 'https://static.rust-lang.org/dist/2021-01-26/cargo-nightly-x86_64-unknown-linux-gnu.tar.xz'
  6.1 MiB /   6.1 MiB (100 %)   2.0 MiB/s in  4s ETA:  0s
info: downloading component 'clippy'
  2.4 MiB /   2.4 MiB (100 %)   2.0 MiB/s in  1s ETA:  0s
info: downloading component 'rust-docs'
 14.9 MiB /  14.9 MiB (100 %)   4.4 MiB/s in  4s ETA:  0s
info: downloading component 'rust-std'
 25.0 MiB /  25.0 MiB (100 %)   4.8 MiB/s in  6s ETA:  0s
info: downloading component 'rustc'
 50.6 MiB /  50.6 MiB (100 %)   5.3 MiB/s in 13s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: using up to 500.0 MiB of RAM to unpack components
info: installing component 'clippy'
info: installing component 'rust-docs'
 14.9 MiB /  14.9 MiB (100 %)   7.1 MiB/s in  1s ETA:  0s
info: installing component 'rust-std'
 25.0 MiB /  25.0 MiB (100 %)   8.0 MiB/s in  5s ETA:  0s
info: installing component 'rustc'
 50.6 MiB /  50.6 MiB (100 %)  11.3 MiB/s in  5s ETA:  0s
info: installing component 'rustfmt'

  nightly-x86_64-unknown-linux-gnu installed - rustc 1.51.0-nightly (f4eb5d9f7 2021-01-25)

安装的时候也可以指定具体的版本信息,默认安装最新的.

安装好后怎么使用呢?

方式一:比较简单的方式是直接安装加更改当前系统默认的channel

 $ rustup default nightly

这种方式连上面的安装步骤都一起做了,直接再执行cargo build 都是使用的nightly channel编译构建项目了,也就是原来使用stable的项目现在也改成nightly了,可能我们并不想都改,咋办?能不是只是临时的用下,可以的:

方式二:使用rustup run指定channel

$ rustup run nightly cargo build

要是就临时这么写一次也没什么,如果用的多了cargo build前面总是要多敲一串难免麻烦,能不能在当前项目中就默认是nightly,不影响其它项目呢?也是可以的.

方式三: 使用rustup overwrite设置当前项目使用的channel 

进入项目目录执行:

$ rustup override set nightly

再执行cargo build就不报错了.

问题解决

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个不安分的程序员

祝您财源广进

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值