Are they the same?

Cargo.toml

cargo-features = ["edition2021"]
[package]
edition = "2021"

My question is, does the line:
cargo-features = ["edition2021"]
have same meaning as:
edition = "2021"

If the answer is yes, then it should not allow to compile.

No, these aren't the same.

Check out the documentation for "edition2021" in Rust 1.55.0: Unstable Features - The Cargo Book

What it did was enable support for edition = "2021" in nightly compilers prior to Rust 1.56.0. So, it never actually changed the edition, it just let you try out changing the edition before said edition was stabilized.

As of Rust 1.56.0, edition = "2021" has stabilized, and cargo-features = ["edition2021"] does nothing.

Thanks for the info.
Then some warning should be emitted about unused statement/declaration.

On my compiler, a warning is emitted:

$ cargo check
warning: the cargo feature `edition2021` has been stabilized in the 1.56 release and is no longer necessary to be listed in the manifest
  See https://doc.rust-lang.org/cargo/reference/manifest.html#the-edition-field for more information about using this feature.
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s

Have you updated to Rust 1.56.0?

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.