【问题标题】:rust unable to run edition2021rust 无法运行 edition2021
【发布时间】:2022-08-21 02:51:04
【问题描述】:

我正在尝试在 rust 中运行一个项目。我一直遇到这个 2021 版错误:

% rustc --version
rustc 1.60.0-nightly (a7e2e3396 2022-01-08)

我跑了这一切:

If you are trying to migrate from the previous edition (2018), the
process requires following these steps:

1. Start with edition = \"2018\" in Cargo.toml
2. Run cargo fix --edition
3. Modify Cargo.toml to set edition = \"2021\"
4. Run cargo build or cargo test to verify the fixes worked 

我不断收到此错误:

Failed to obtain package metadata: Error during execution of cargo metadata: error: failed to parse manifest at /workdir/program/Cargo.toml

Caused by:
  the cargo feature edition2021 requires a nightly version of Cargo, but this is the stable channel 

我在这里完全不知所措。我发现了很多相互矛盾的信息。我已经更改了目录,在 SO 上找到了这样的答案:Unable to specify `edition2021` in order to use unstable packages in Rust

我在这里完全不知所措。我在这里缺少的步骤是什么?我在 MacOS Big Sur 上。

  • 看起来您正在运行稳定的 Cargo,但每晚都运行 rustc。输入cargo --version 的结果是什么?
  • @ChayimFriedman cargo 1.60.0-nightly (358e79fe5 2022-01-04)
  • 你解决了吗?

标签: rust rust-cargo


【解决方案1】:

似乎,对于您的特定包,使用 cargo (rustc) stable 是因为“......但这是稳定的渠道”。也许通过 rustup 为您的包定义了不同的编译器通道。然后始终使用此特定通道,而不管全局默认值如何。如果你是里面包,您可以使用rustup show 显示活动工具链。也许它说该软件包使用了 stable 。然后考虑使用rustup override unset 删除此覆盖并尝试再次运行它。

编辑:因为 2021 版已经稳定了一段时间,您可以考虑使用 rustup update 更新 rustc 和 cargo,然后如果您不使用任何其他夜间功能,您的项目应该能够使用稳定的编译器运行。

【讨论】:

    【解决方案2】:

    不是使用cargo-features = ["edition2021"] 设置。它已经过时,不能再使用了。将其从所有 Cargo.toml 文件中完全删除。添加它的指令是由一个过时的、不受支持的、实验性的编译器版本打印的,你不应该再使用它了。

    您不再需要为 2021 版使用夜间版本。自 2021 年 12 月以来,它一直稳定且可广泛使用。您只需将 Rust 更新到稳定版本 1.56 或更高版本。

    如果您碰巧使用了来自缓慢移动的 Linux 发行版的过时 Rust 包,请将其卸载,然后通过 https://rustup.rs 安装 Rust。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      • 2021-01-03
      • 1970-01-01
      • 2018-04-05
      • 2019-09-07
      • 1970-01-01
      相关资源
      最近更新 更多