Skip to content

Commit

Permalink
feat: Stabilize Edition 2024 (rust-lang#14828)
Browse files Browse the repository at this point in the history
### What does this PR try to resolve?

### How should we test and review this PR?

### Additional information
  • Loading branch information
ehuss authored Nov 25, 2024
2 parents f1767d0 + 81411ec commit 4c39aaf
Show file tree
Hide file tree
Showing 66 changed files with 189 additions and 312 deletions.
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`

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

0 comments on commit 4c39aaf

Please sign in to comment.