admin管理员组文章数量:1650765
今天在编译一个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/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就不报错了.
问题解决
本文标签: 三种方式releasestablefeature
版权声明:本文标题:#![feature]` may not be used on the stable release channel 问题解决及设置Rust Channel的三种方式 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729533371a1205098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论