3

I'm trying to run a project in rust. I keep running into this edition 2021 error:

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

I ran all this:

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 

I keep getting this error:

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 

I'm at a total loss here. I've found a lot of conflicting information. I've changed directories, found answers on SO like this: Unable to specify `edition2021` in order to use unstable packages in Rust

I'm at a total loss here. What is the step I'm missing here? I'm on MacOS Big Sur.

dizzystar
  • 1,055
  • 12
  • 22

2 Answers2

1

It seems that, for your specific package, cargo (rustc) stable is used because of "...but this is the stable channel". Maybe a different compiler channel is defined for your package via rustup. Then this specific channel is always used, regardless of the global default. If you are inside the package, you can use rustup show to display the active toolchain. Maybe it says that stable is used for that package. Then consider removing this override with rustup override unset and try running it again.

EDIT: Because edition 2021 is stable for a while, you might consider updating rustc and cargo with rustup update, and then your project should be able to run with the stable compiler if you do not use any other nightly features.

linuskmr
  • 727
  • 3
  • 13
1

Do not use cargo-features = ["edition2021"] setting. It's obsolete and must not be used any more. Completely remove it from all Cargo.toml files. The instruction to add this was printed by an outdated, unsupported, experimental compiler version that you're not supposed to be using any more.

You don't need to use a nightly version for the 2021 edition any more. It's been stable and widely usable since December 2021. You just need to update your Rust to a stable version 1.56 or later.

If you happen to be using an outdated Rust package from a slow-moving Linux distribution, uninstall it, and install Rust via https://rustup.rs instead.

Kornel
  • 97,764
  • 37
  • 219
  • 309
  • Can you please cite a reference for "obsolete and must be used anymore"? I'm not doubting what you're saying here, it would just be helpful for a Rust beginner (me) to see the context. I thought backward-compatibility was one of Rust's selling points, and this is not making that case very well. – TheDudeAbides Aug 04 '23 at 22:46
  • `cargo-features =` exists only for opting in to unfinished, experimental, unstable "nightly" features. Once something is released for real, it's not a "nightly" feature any more, and nightly-opt-in for it stops working. – Kornel Aug 21 '23 at 17:30