无法指定“edition2021”以便在 Rust 中使用不稳定的包

Avi*_*ava 43 rust substrate polkadot

我想通过 Cargo 运行一个示例,但遇到错误:

error: failed to parse manifest at `/Users/aviralsrivastava/dev/subxt/Cargo.toml`
Run Code Online (Sandbox Code Playgroud)

完整的堆栈跟踪是:

error: failed to parse manifest at `/Users/aviralsrivastava/dev/subxt/Cargo.toml`

Caused by:
  feature `edition2021` is required

  The package requires the Cargo feature called `edition2021`, but that feature is not stabilized in this version of Cargo (1.56.0-nightly (b51439fd8 2021-08-09)).
  Consider adding `cargo-features = ["edition2021"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
  See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature.
Run Code Online (Sandbox Code Playgroud)

根据建议,我继续修改 Cargo.toml:

  Consider adding `cargo-features = ["edition2021"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
diff --git a/Cargo.toml b/Cargo.toml
index 26a02c7..186d09b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [workspace]
 members = [".", "cli", "codegen", "macro"]
-
+cargo-features = ["edition2021"]
 [package]
 name = "subxt"
 version = "0.15.0"
(END)
Run Code Online (Sandbox Code Playgroud)

我仍然面临同样的错误,就好像 toml 文件中没有任何更改一样。

如何解决上述错误以便使用不稳定的软件包?

Aur*_*ier 58

更新 Rust 以满足 2021 年新版本的要求。

rustup default nightly && rustup update

感谢@ken。是的,您也可以使用该stable频道!

但我nightly个人很喜欢。

  • 今天早上我使用我的 Intel Mac 遇到了这个问题,只是在稳定分支上运行了“rustup update”,这就足够了......整个周末我都在我的 M1 Mac 上使用 2021 版本,没有问题,但也许它正在运行更新后的版本。无论如何,2021 年现在已经是稳定版本了。 (2认同)

小智 18

2021 版现已成为稳定频道的一部分。

正如我所发生的那样,您可能只需要通过运行来更新稳定版本rustup update stable

这应该可以解决问题,并且不需要您切换到夜间频道。

  • 这应该是现在的首要答案! (2认同)

小智 5

尝试:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env && rustup default nightly && rustup update
Run Code Online (Sandbox Code Playgroud)