`#![feature]` 可能无法在稳定发布通道上使用

whe*_*ler 11 rust

我正在尝试使用clap板条箱进行一些参数解析。但是,当我将其添加到我的时Cargo.toml,我会收到以下错误cargo build

$ cargo build
   Compiling rustix v0.36.5
error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /home/wheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.5/src/lib.rs:99:26
   |
99 | #![cfg_attr(rustc_attrs, feature(rustc_attrs))]
   |                          ^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/wheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.5/src/lib.rs:116:5
    |
116 |     feature(core_intrinsics)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/wheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.5/src/lib.rs:116:13
    |
116 |     feature(core_intrinsics)
    |             ^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `rustix` due to 3 previous errors
Run Code Online (Sandbox Code Playgroud)

文档中没有任何内容clap表明它需要使用夜间构建。我不明白为什么会发生这种情况,因此我创建了一个虚拟机来尝试复制该问题(使用 Vagrant)。这是 Vagrant 文件:

$ cargo build
   Compiling rustix v0.36.5
error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /home/wheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.5/src/lib.rs:99:26
   |
99 | #![cfg_attr(rustc_attrs, feature(rustc_attrs))]
   |                          ^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/wheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.5/src/lib.rs:116:5
    |
116 |     feature(core_intrinsics)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/wheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.36.5/src/lib.rs:116:13
    |
116 |     feature(core_intrinsics)
    |             ^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `rustix` due to 3 previous errors
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,虚拟机会更新、安装 Rust,并编译我的小示例程序(它与我在主机系统上的vagrant up完全相同)。main.rsCargo.toml

为什么clap我的主机上需要夜间版本,但测试虚拟机上不需要?

whe*_*ler 14

target导致此问题的目录中缓存了某些内容。我删除了该target目录并重新运行cargo build,问题就消失了。

  • 您还可以运行 Cargo clean,而不是手动删除目录。 (5认同)

Mii*_*iao -4

要使用feature属性,您需要nightly发布通道。要切换到每晚,请执行rustup default nightly命令。