Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Stabilize Edition 2024 #14828

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub type AllowFeatures = BTreeSet<String>;
/// - Set [`LATEST_UNSTABLE`] to None.
/// - Set [`LATEST_STABLE`] to the new version.
/// - Update [`is_stable`] to `true`.
/// - Set [`first_version`] to the version it will be released.
/// - Set the editionNNNN feature to stable in the [`features!`] macro invocation below.
/// - Update any tests that are affected.
/// - Update the man page for the `--edition` flag.
Expand All @@ -178,6 +179,7 @@ pub type AllowFeatures = BTreeSet<String>;
/// [`LATEST_UNSTABLE`]: Edition::LATEST_UNSTABLE
/// [`LATEST_STABLE`]: Edition::LATEST_STABLE
/// [this example]: https://github.com/rust-lang/cargo/blob/3ebb5f15a940810f250b68821149387af583a79e/src/doc/src/reference/unstable.md?plain=1#L1238-L1264
/// [`first_version`]: Edition::first_version
/// [`is_stable`]: Edition::is_stable
/// [`toml`]: crate::util::toml
/// [`features!`]: macro.features.html
Expand All @@ -200,9 +202,9 @@ impl Edition {
/// The latest edition that is unstable.
///
/// This is `None` if there is no next unstable edition.
pub const LATEST_UNSTABLE: Option<Edition> = Some(Edition::Edition2024);
pub const LATEST_UNSTABLE: Option<Edition> = None;
/// The latest stable edition.
pub const LATEST_STABLE: Edition = Edition::Edition2021;
pub const LATEST_STABLE: Edition = Edition::Edition2024;
pub const ALL: &'static [Edition] = &[
Self::Edition2015,
Self::Edition2018,
Expand All @@ -223,7 +225,7 @@ impl Edition {
Edition2015 => None,
Edition2018 => Some(semver::Version::new(1, 31, 0)),
Edition2021 => Some(semver::Version::new(1, 56, 0)),
Edition2024 => None,
Edition2024 => Some(semver::Version::new(1, 85, 0)),
}
}

Expand All @@ -234,7 +236,7 @@ impl Edition {
Edition2015 => true,
Edition2018 => true,
Edition2021 => true,
Edition2024 => false,
Edition2024 => true,
}
}

Expand Down Expand Up @@ -507,7 +509,7 @@ features! {
(stable, workspace_inheritance, "1.64", "reference/unstable.html#workspace-inheritance"),

/// Support for 2024 edition.
(unstable, edition2024, "", "reference/unstable.html#edition-2024"),
(stable, edition2024, "1.85", "reference/manifest.html#the-edition-field"),

/// Allow setting trim-paths in a profile to control the sanitisation of file paths in build outputs.
(unstable, trim_paths, "", "reference/unstable.html#profile-trim-paths-option"),
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ autoexamples = false
autolib = false
autotests = false
build = false
edition = "2021"
edition = "2024"
name = "test-"

[profile.release]
Expand Down Expand Up @@ -605,7 +605,7 @@ autoexamples = false
autolib = false
autotests = false
build = false
edition = "2021"
edition = "2024"
name = "test-"

[profile.release]
Expand Down
4 changes: 1 addition & 3 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,7 @@ pub fn to_real_manifest(
// features.require(Feature::edition20xx())?;
// }
// ```
if edition == Edition::Edition2024 {
features.require(Feature::edition2024())?;
} else if !edition.is_stable() {
if !edition.is_stable() {
// Guard in case someone forgets to add .require()
return Err(util::errors::internal(format!(
"edition {} should be gated",
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/generated_txt/cargo-init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ OPTIONS
Create a package with a library target (src/lib.rs).

--edition edition
Specify the Rust edition to use. Default is 2021. Possible values:
Specify the Rust edition to use. Default is 2024. Possible values:
2015, 2018, 2021, 2024

--name name
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/generated_txt/cargo-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OPTIONS
Create a package with a library target (src/lib.rs).

--edition edition
Specify the Rust edition to use. Default is 2021. Possible values:
Specify the Rust edition to use. Default is 2024. Possible values:
2015, 2018, 2021, 2024

--name name
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/includes/options-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Create a package with a library target (`src/lib.rs`).
{{/option}}

{{#option "`--edition` _edition_" }}
Specify the Rust edition to use. Default is 2021.
Specify the Rust edition to use. Default is 2024.
Possible values: 2015, 2018, 2021, 2024
{{/option}}

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This is the default behavior.</dd>


<dt class="option-term" id="option-cargo-init---edition"><a class="option-anchor" href="#option-cargo-init---edition"></a><code>--edition</code> <em>edition</em></dt>
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
<dd class="option-desc">Specify the Rust edition to use. Default is 2024.
Possible values: 2015, 2018, 2021, 2024</dd>


Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This is the default behavior.</dd>


<dt class="option-term" id="option-cargo-new---edition"><a class="option-anchor" href="#option-cargo-new---edition"></a><code>--edition</code> <em>edition</em></dt>
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
<dd class="option-desc">Specify the Rust edition to use. Default is 2024.
Possible values: 2015, 2018, 2021, 2024</dd>


Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/getting-started/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This is all we need to get started. First, let’s check out `Cargo.toml`:
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
```
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/guide/creating-a-new-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Let’s take a closer look at `Cargo.toml`:
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/guide/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ crates:
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
time = "0.1.12"
Expand Down
8 changes: 4 additions & 4 deletions src/doc/src/reference/build-script-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Here we can see that we have a `build.rs` build script and our binary in
[package]
name = "hello-from-generated-code"
version = "0.1.0"
edition = "2021"
edition = "2024"
```

Let’s see what’s inside the build script:
Expand Down Expand Up @@ -148,7 +148,7 @@ Pretty similar to before! Next, the manifest:
[package]
name = "hello-world-from-c"
version = "0.1.0"
edition = "2021"
edition = "2024"
```

For now we’re not going to use any build dependencies, so let’s take a look at
Expand Down Expand Up @@ -298,7 +298,7 @@ with `pkg-config` installed. Let's start by setting up the manifest:
[package]
name = "libz-sys"
version = "0.1.0"
edition = "2021"
edition = "2024"
links = "z"

[build-dependencies]
Expand Down Expand Up @@ -385,7 +385,7 @@ Here's an example:
[package]
name = "zuser"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
libz-sys = "1.0.25"
Expand Down
4 changes: 2 additions & 2 deletions src/doc/src/reference/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ examples, etc.
```toml
[package]
# ...
edition = '2021'
edition = '2024'
```

Most manifests have the `edition` field filled in automatically by [`cargo new`]
with the latest stable edition. By default `cargo new` creates a manifest with
the 2021 edition currently.
the 2024 edition currently.

If the `edition` field is not present in `Cargo.toml`, then the 2015 edition is
assumed for backwards compatibility. Note that all manifests
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in `Cargo.toml`:
[package]
name = "my-project"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
other-crate = { version = "1.0", registry = "my-registry" }
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ resolver = "2"
- `"2"` ([`edition = "2021"`](manifest.md#the-edition-field) default): Introduces changes in [feature
unification](#features). See the [features chapter][features-2] for more
details.
- `"3"` (requires Rust 1.84+): Change the default for [`resolver.incompatible-rust-versions`] from `allow` to `fallback`
- `"3"` ([`edition = "2024"`](manifest.md#the-edition-field) default, requires Rust 1.84+): Change the default for [`resolver.incompatible-rust-versions`] from `allow` to `fallback`
Copy link
Contributor

@weiznich weiznich Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to point again to RFC-2052 especially to the hard constraints section there:

Warning-free code on edition N must compile on edition N+1 and have the same behavior.

Given that this changes the resolver behavior you can end up in situations that result in broken builds if you specify a minimal supported rust version and a too broad minimal dependency version. That can then result in a changed version resolution to an dependency version which does not contain a public element that is used by the actual crate.

No warning about the possible broken build is emitted with the 2021 edition!

Ed Page pointed out before that this only happens if there is no Cargo.lock file as otherwise dependency resolution is not rerun on edition updates. Also he pointed out that this code is already faulty.

I argue again that neither arguments are valid here as:

  • Projects without Cargo.lock file checked in git repositories where the default at the introduction of the 2021 edition, so cargo must expect that such projects still exists. After all these compile without warning on the latest cargo version
  • A broken minimal dependency version only caused issues with unstable features (-Z minimal-version) in the past, not with any updates (at least as long as the dependency follows semver, but that's assumed as default). So this is a new built-error mode. (Or worded differently the rust compiler itself does also introduce warning periods for similar "fixes")

EDIT: To be clear here, I'm not calling for not stabilizing this feature, I'm just asking for adding the warning required by the RFC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed in #14754 and the Cargo team still checked their boxes and didn't raise a concern to block FCP.

Copy link
Contributor

@weiznich weiznich Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know the cargo team is responsible for managing cargo. The edition is a language feature, which means the cargo team is not the only responsible team to decide whether something violates the relevant RFC or not.

In addition to that above: Completing the FCP does not change fact that this violates that hard constraint as no such warning is emitted today. I would even argue that this might indicate that the cargo team knowingly decides to violate this RFC and therefore break the given stability guarantees (again).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moderator note: both of you have stated everything there is to it from your perspectives. Further discussion between you two is not fruitful in my opinion. So other cargo team members can chime in, but I would like it if you two refrained from further commentary on this topic unless asked to by cargo team members.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cargo team discussed these concerns, fully understands these concerns, and does not feel that a change is needed here. We do not think a warning could or should be provided here, due among other reasons to the high likelihood of false positives. We have been carefully considering the ecosystem impact of many different possible approaches to integrating MSRV into the dependency resolver, and we want to highlight that the experience of crate maintainers in many different circumstances has always been our foremost consideration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehuss I'm sorry to write that but your response does again not address the core of my concern. So let it me boil down to a simple question:

Which RCF or similar language level decision does exempt the cargo team from the following the rules outlined in RFC-2052?

Can you or a different team member answer this simple question instead of bringing up yet another iteration of excuses why this feature is important or why the given example is already broken.


The resolver is a global option that affects the entire workspace. The
`resolver` version in dependencies is ignored, only the value in the top-level
Expand Down
34 changes: 7 additions & 27 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ Each new feature described below should explain how to use it.
* [codegen-backend](#codegen-backend) --- Select the codegen backend used by rustc.
* [per-package-target](#per-package-target) --- Sets the `--target` to use for each individual package.
* [artifact dependencies](#artifact-dependencies) --- Allow build artifacts to be included into other build artifacts and build them for different targets.
* [Edition 2024](#edition-2024) — Adds support for the 2024 Edition.
* [Profile `trim-paths` option](#profile-trim-paths-option) --- Control the sanitization of file paths in build outputs.
* [`[lints.cargo]`](#lintscargo) --- Allows configuring lints for Cargo.
* [path bases](#path-bases) --- Named base directories for path dependencies.
Expand Down Expand Up @@ -1363,32 +1362,6 @@ Differences between `cargo run --manifest-path <path>` and `cargo <path>`

### Documentation Updates

## Edition 2024
* Tracking Issue: (none created yet)
* RFC: [rust-lang/rfcs#3501](https://github.com/rust-lang/rfcs/pull/3501)

Support for the 2024 [edition] can be enabled by adding the `edition2024`
unstable feature to the top of `Cargo.toml`:

```toml
cargo-features = ["edition2024"]

[package]
name = "my-package"
version = "0.1.0"
edition = "2024"
```

If you want to transition an existing project from a previous edition, then
`cargo fix --edition` can be used on the nightly channel. After running `cargo
fix`, you can switch the edition to 2024 as illustrated above.

This feature is very unstable, and is only intended for early testing and
experimentation. Future nightly releases may introduce changes for the 2024
edition that may break your build.

[edition]: ../../edition-guide/index.html

## Profile `trim-paths` option

* Tracking Issue: [rust-lang/cargo#12137](https://github.com/rust-lang/cargo/issues/12137)
Expand Down Expand Up @@ -2013,3 +1986,10 @@ default behavior.

See the [build script documentation](build-scripts.md#rustc-check-cfg) for information
about specifying custom cfgs.

## Edition 2024

The 2024 edition has been stabilized in the 1.85 release.
See the [`edition` field](manifest.md#the-edition-field) for more information on setting the edition.
See [`cargo fix --edition`](../commands/cargo-fix.md) and [The Edition Guide](../../edition-guide/index.html) for more information on migrating existing projects.

2 changes: 1 addition & 1 deletion src/doc/src/reference/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ resolver = "2"
[package]
name = "hello_world" # the name of the package
version = "0.1.0" # the current version, obeying semver
edition = "2021" # the edition, will have no effect on a resolver used in the workspace
edition = "2024" # the edition, will have no effect on a resolver used in the workspace
authors = ["Alice <[email protected]>", "Bob <[email protected]>"]
```

Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-init.1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
.sp
\fB\-\-edition\fR \fIedition\fR
.RS 4
Specify the Rust edition to use. Default is 2021.
Specify the Rust edition to use. Default is 2024.
Possible values: 2015, 2018, 2021, 2024
.RE
.sp
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-new.1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
.sp
\fB\-\-edition\fR \fIedition\fR
.RS 4
Specify the Rust edition to use. Default is 2021.
Specify the Rust edition to use. Default is 2024.
Possible values: 2015, 2018, 2021, 2024
.RE
.sp
Expand Down
Loading