Skip to content

Commit

Permalink
feat: Stabilize Edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 15, 2024
1 parent 88edf01 commit 8b671be
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,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/unstable.html#edition-2024"),

/// 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: 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/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.

61 changes: 11 additions & 50 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,12 @@ fn dev_dependencies2() {
"#]]).run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn dev_dependencies2_2024() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -861,7 +859,6 @@ fn dev_dependencies2_2024() {
.file("a/src/lib.rs", "")
.build();
p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -949,14 +946,12 @@ fn build_dependencies2() {
"#]]).run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn build_dependencies2_2024() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -979,7 +974,6 @@ fn build_dependencies2_2024() {
.file("a/src/lib.rs", "")
.build();
p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1060,14 +1054,12 @@ fn lib_crate_type2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn lib_crate_type2_2024() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.5.0"
Expand All @@ -1082,7 +1074,6 @@ fn lib_crate_type2_2024() {
.file("src/lib.rs", "pub fn foo() {}")
.build();
p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1154,14 +1145,12 @@ fn bin_crate_type2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn bin_crate_type2_2024() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.5.0"
Expand All @@ -1177,7 +1166,6 @@ fn bin_crate_type2_2024() {
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1268,14 +1256,12 @@ fn examples_crate_type2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn examples_crate_type2_2024() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.5.0"
Expand Down Expand Up @@ -1307,7 +1293,6 @@ fn examples_crate_type2_2024() {
)
.build();
p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1411,16 +1396,14 @@ fn cargo_platform_build_dependencies2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn cargo_platform_build_dependencies2_2024() {
let host = rustc_host();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.5.0"
Expand All @@ -1444,7 +1427,6 @@ fn cargo_platform_build_dependencies2_2024() {
.build();

p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1543,16 +1525,14 @@ fn cargo_platform_dev_dependencies2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn cargo_platform_dev_dependencies2_2024() {
let host = rustc_host();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.5.0"
Expand All @@ -1575,7 +1555,6 @@ fn cargo_platform_dev_dependencies2_2024() {
.build();

p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1675,14 +1654,12 @@ fn default_features2() {
"#]]).run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn default_features2_2024() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.1.0"
Expand Down Expand Up @@ -1712,7 +1689,6 @@ fn default_features2_2024() {
.build();

p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -1852,7 +1828,7 @@ fn workspace_default_features2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn workspace_default_features2_2024() {
let p = project()
.file(
Expand All @@ -1869,8 +1845,6 @@ fn workspace_default_features2_2024() {
.file(
"workspace_only/Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "workspace_only"
version = "0.1.0"
Expand All @@ -1885,8 +1859,6 @@ fn workspace_default_features2_2024() {
.file(
"dep_workspace_only/Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "dep_workspace_only"
version = "0.1.0"
Expand All @@ -1898,8 +1870,6 @@ fn workspace_default_features2_2024() {
.file(
"package_only/Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "package_only"
version = "0.1.0"
Expand All @@ -1914,8 +1884,6 @@ fn workspace_default_features2_2024() {
.file(
"dep_package_only/Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "dep_package_only"
version = "0.1.0"
Expand All @@ -1927,7 +1895,6 @@ fn workspace_default_features2_2024() {
.build();

p.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to load manifest for workspace member `[ROOT]/foo/workspace_only`
Expand Down Expand Up @@ -1972,14 +1939,12 @@ fn lib_proc_macro2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn lib_proc_macro2_2024() {
let foo = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -1992,7 +1957,6 @@ fn lib_proc_macro2_2024() {
.build();

foo.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down Expand Up @@ -2063,14 +2027,12 @@ fn bin_proc_macro2() {
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
#[cargo_test]
fn bin_proc_macro2_2024() {
let foo = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.5.0"
Expand All @@ -2087,7 +2049,6 @@ fn bin_proc_macro2_2024() {
.build();

foo.cargo("check")
.masquerade_as_nightly_cargo(&["edition2024"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Expand Down
Loading

0 comments on commit 8b671be

Please sign in to comment.