【问题标题】:`#![feature]` may not be used on the stable release channel`#![feature]` 可能无法在稳定发布频道上使用
【发布时间】:2022-12-10 14:08:27
【问题描述】:

我正在尝试使用 clap crate 进行一些参数解析。但是,当我将它添加到我的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

clap 的文档中没有任何内容表明它需要使用 nighly 构建。我不明白为什么会这样,所以我创建了一个虚拟机来尝试重现这个问题(使用 Vagrant)。这是 Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "generic/fedora37"

  config.vm.provision "shell", inline: <<~'EOF'
    set -e
    set -x
    sudo dnf update -y
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    source "$HOME/.cargo/env"
    mkdir -p test-project
    cd test-project
    cat << 'EOFF' | sed -r 's/^ {2}//' > Cargo.toml
      [package]
      name = "rpg"
      version = "0.1.0"
      edition = "2021"
      
      [dependencies]
      clap = { version = "4.0.29", features = ["derive"] }
    EOFF
    cat Cargo.toml
    mkdir -p src
    cd src
    touch main.rs
    cat << 'EOFF' | sed -r 's/^ {2}//' > main.rs
      use clap::Parser;
      
      /// Simple program to greet a person
      #[derive(Parser, Debug)]
      #[command(author, version, about, long_about = None)]
      struct Args {
         /// Name of the person to greet
         #[arg(short, long)]
         name: String,
      
         /// Number of times to greet
         #[arg(short, long, default_value_t = 1)]
         count: u8,
      }
      
      fn main() {
         let args = Args::parse();
      
         for _ in 0..args.count {
             println!("Hello {}!", args.name)
         }
      }
    EOFF
    cat main.rs
    cd ..
    cargo build

  EOF
end

但是当我执行 vagrant up 时,VM 会更新、安装 rust 并编译我的小示例程序(它与主机系统上的 main.rsCargo.toml 完全相同)。

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

【问题讨论】:

  • 像这样的错误通常来自过时的 Rust 工具链。在这两种情况下,您运行的是什么版本的 Rust?
  • @cafce25 的确如此。不久前我自己偶然发现了这个。 rustup update 帮我修好了。
  • stable-x86_64-unknown-linux-gnu unchanged - rustc 1.65.0 (897e37553 2022-11-02)是我做rustup update时报的版本。

标签: rust


【解决方案1】:

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

【讨论】:

  • 这很明显,但该功能在 rustix 中是一个依赖项,一开始就不应该启用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-22
  • 1970-01-01
  • 2016-09-21
  • 2018-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多