Skip to content

Commit d74bc47

Browse files
committed
Auto merge of #12771 - Muscraft:edition-2024, r=epage
feat: Add `Edition2024` [RFC for `Edition2024`](rust-lang/rfcs#3501). While the RFC is not yet merged, this follows rustc which added the 2024 edition previously in rust-lang/rust#94461 This PR adds `Edition2024` as a possible value for `edition = "xxxx"`. I did this by following the [guide here](https://github.com/rust-lang/cargo/blob/ed0a7873107f48079a424da2920f7d434fd22fdc/src/cargo/core/features.rs#L163-L174).
2 parents 3591db0 + b2b3cfa commit d74bc47

File tree

13 files changed

+61
-19
lines changed

13 files changed

+61
-19
lines changed

src/cargo/core/features.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,22 @@ pub enum Edition {
205205
Edition2018,
206206
/// The 2021 edition
207207
Edition2021,
208+
/// The 2024 edition
209+
Edition2024,
208210
}
209211

210212
impl Edition {
211213
/// The latest edition that is unstable.
212214
///
213215
/// This is `None` if there is no next unstable edition.
214-
pub const LATEST_UNSTABLE: Option<Edition> = None;
216+
pub const LATEST_UNSTABLE: Option<Edition> = Some(Edition::Edition2024);
215217
/// The latest stable edition.
216218
pub const LATEST_STABLE: Edition = Edition::Edition2021;
217219
/// Possible values allowed for the `--edition` CLI flag.
218220
///
219221
/// This requires a static value due to the way clap works, otherwise I
220222
/// would have built this dynamically.
221-
pub const CLI_VALUES: [&'static str; 3] = ["2015", "2018", "2021"];
223+
pub const CLI_VALUES: [&'static str; 4] = ["2015", "2018", "2021", "2024"];
222224

223225
/// Returns the first version that a particular edition was released on
224226
/// stable.
@@ -228,6 +230,7 @@ impl Edition {
228230
Edition2015 => None,
229231
Edition2018 => Some(semver::Version::new(1, 31, 0)),
230232
Edition2021 => Some(semver::Version::new(1, 56, 0)),
233+
Edition2024 => None,
231234
}
232235
}
233236

@@ -238,6 +241,7 @@ impl Edition {
238241
Edition2015 => true,
239242
Edition2018 => true,
240243
Edition2021 => true,
244+
Edition2024 => false,
241245
}
242246
}
243247

@@ -250,6 +254,7 @@ impl Edition {
250254
Edition2015 => None,
251255
Edition2018 => Some(Edition2015),
252256
Edition2021 => Some(Edition2018),
257+
Edition2024 => Some(Edition2021),
253258
}
254259
}
255260

@@ -260,7 +265,8 @@ impl Edition {
260265
match self {
261266
Edition2015 => Edition2018,
262267
Edition2018 => Edition2021,
263-
Edition2021 => Edition2021,
268+
Edition2021 => Edition2024,
269+
Edition2024 => Edition2024,
264270
}
265271
}
266272

@@ -286,6 +292,7 @@ impl Edition {
286292
Edition2015 => false,
287293
Edition2018 => true,
288294
Edition2021 => true,
295+
Edition2024 => false,
289296
}
290297
}
291298

@@ -298,6 +305,7 @@ impl Edition {
298305
Edition2015 => false,
299306
Edition2018 => true,
300307
Edition2021 => false,
308+
Edition2024 => false,
301309
}
302310
}
303311

@@ -316,6 +324,7 @@ impl fmt::Display for Edition {
316324
Edition::Edition2015 => f.write_str("2015"),
317325
Edition::Edition2018 => f.write_str("2018"),
318326
Edition::Edition2021 => f.write_str("2021"),
327+
Edition::Edition2024 => f.write_str("2024"),
319328
}
320329
}
321330
}
@@ -326,13 +335,14 @@ impl FromStr for Edition {
326335
"2015" => Ok(Edition::Edition2015),
327336
"2018" => Ok(Edition::Edition2018),
328337
"2021" => Ok(Edition::Edition2021),
329-
s if s.parse().map_or(false, |y: u16| y > 2021 && y < 2050) => bail!(
338+
"2024" => Ok(Edition::Edition2024),
339+
s if s.parse().map_or(false, |y: u16| y > 2024 && y < 2050) => bail!(
330340
"this version of Cargo is older than the `{}` edition, \
331-
and only supports `2015`, `2018`, and `2021` editions.",
341+
and only supports `2015`, `2018`, `2021`, and `2024` editions.",
332342
s
333343
),
334344
s => bail!(
335-
"supported edition values are `2015`, `2018`, or `2021`, \
345+
"supported edition values are `2015`, `2018`, `2021`, or `2024`, \
336346
but `{}` is unknown",
337347
s
338348
),
@@ -483,6 +493,9 @@ features! {
483493

484494
// Allow specifying rustflags directly in a profile
485495
(stable, workspace_inheritance, "1.64", "reference/unstable.html#workspace-inheritance"),
496+
497+
// Support for 2024 edition.
498+
(unstable, edition2024, "", "reference/unstable.html#edition-2024"),
486499
}
487500

488501
pub struct Feature {

src/cargo/util/toml/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,12 @@ impl TomlManifest {
569569
// Add these lines if start a new unstable edition.
570570
// ```
571571
// if edition == Edition::Edition20xx {
572-
// features.require(Feature::edition20xx))?;
572+
// features.require(Feature::edition20xx())?;
573573
// }
574574
// ```
575-
if !edition.is_stable() {
575+
if edition == Edition::Edition2024 {
576+
features.require(Feature::edition2024())?;
577+
} else if !edition.is_stable() {
576578
// Guard in case someone forgets to add .require()
577579
return Err(util::errors::internal(format!(
578580
"edition {} should be gated",

src/doc/man/generated_txt/cargo-init.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ OPTIONS
3131

3232
--edition edition
3333
Specify the Rust edition to use. Default is 2021. Possible values:
34-
2015, 2018, 2021
34+
2015, 2018, 2021, 2024
3535

3636
--name name
3737
Set the package name. Defaults to the directory name.

src/doc/man/generated_txt/cargo-new.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OPTIONS
2626

2727
--edition edition
2828
Specify the Rust edition to use. Default is 2021. Possible values:
29-
2015, 2018, 2021
29+
2015, 2018, 2021, 2024
3030

3131
--name name
3232
Set the package name. Defaults to the directory name.

src/doc/man/includes/options-new.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Create a package with a library target (`src/lib.rs`).
1111

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

1717
{{#option "`--name` _name_" }}

src/doc/src/commands/cargo-init.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This is the default behavior.</dd>
4040

4141
<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>
4242
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
43-
Possible values: 2015, 2018, 2021</dd>
43+
Possible values: 2015, 2018, 2021, 2024</dd>
4444

4545

4646
<dt class="option-term" id="option-cargo-init---name"><a class="option-anchor" href="#option-cargo-init---name"></a><code>--name</code> <em>name</em></dt>

src/doc/src/commands/cargo-new.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This is the default behavior.</dd>
3535

3636
<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>
3737
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
38-
Possible values: 2015, 2018, 2021</dd>
38+
Possible values: 2015, 2018, 2021, 2024</dd>
3939

4040

4141
<dt class="option-term" id="option-cargo-new---name"><a class="option-anchor" href="#option-cargo-new---name"></a><code>--name</code> <em>name</em></dt>

src/doc/src/reference/unstable.md

+27
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ For the latest nightly, see the [nightly version] of this page.
9393
* [codegen-backend](#codegen-backend) --- Select the codegen backend used by rustc.
9494
* [per-package-target](#per-package-target) --- Sets the `--target` to use for each individual package.
9595
* [artifact dependencies](#artifact-dependencies) --- Allow build artifacts to be included into other build artifacts and build them for different targets.
96+
* [Edition 2024](#edition-2024) — Adds support for the 2024 Edition.
9697
* Information and metadata
9798
* [Build-plan](#build-plan) --- Emits JSON information on which commands will be run.
9899
* [unit-graph](#unit-graph) --- Emits JSON for Cargo's internal graph structure.
@@ -1271,6 +1272,32 @@ Differences between `cargo run --manifest-path <path>` and `cargo <path>`
12711272

12721273
### Documentation Updates
12731274

1275+
## Edition 2024
1276+
* Tracking Issue: (none created yet)
1277+
* RFC: [rust-lang/rfcs#3501](https://github.com/rust-lang/rfcs/pull/3501)
1278+
1279+
Support for the 2024 [edition] can be enabled by adding the `edition2024`
1280+
unstable feature to the top of `Cargo.toml`:
1281+
1282+
```toml
1283+
cargo-features = ["edition2024"]
1284+
1285+
[package]
1286+
name = "my-package"
1287+
version = "0.1.0"
1288+
edition = "2024"
1289+
```
1290+
1291+
If you want to transition an existing project from a previous edition, then
1292+
`cargo fix --edition` can be used on the nightly channel. After running `cargo
1293+
fix`, you can switch the edition to 2024 as illustrated above.
1294+
1295+
This feature is very unstable, and is only intended for early testing and
1296+
experimentation. Future nightly releases may introduce changes for the 2024
1297+
edition that may break your build.
1298+
1299+
[edition]: ../../edition-guide/index.html
1300+
12741301
# Stabilized and removed features
12751302

12761303
## Compile progress

src/etc/man/cargo-init.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
3737
\fB\-\-edition\fR \fIedition\fR
3838
.RS 4
3939
Specify the Rust edition to use. Default is 2021.
40-
Possible values: 2015, 2018, 2021
40+
Possible values: 2015, 2018, 2021, 2024
4141
.RE
4242
.sp
4343
\fB\-\-name\fR \fIname\fR

src/etc/man/cargo-new.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
3232
\fB\-\-edition\fR \fIedition\fR
3333
.RS 4
3434
Specify the Rust edition to use. Default is 2021.
35-
Possible values: 2015, 2018, 2021
35+
Possible values: 2015, 2018, 2021, 2024
3636
.RE
3737
.sp
3838
\fB\-\-name\fR \fIname\fR

tests/testsuite/cargo_init/help/stdout.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Options:
1212
--bin Use a binary (application) template [default]
1313
--lib Use a library template
1414
--edition <YEAR> Edition to set for the crate generated [possible values: 2015, 2018,
15-
2021]
15+
2021, 2024]
1616
--name <NAME> Set the resulting package name, defaults to the directory name
1717
--registry <REGISTRY> Registry to use
1818
-q, --quiet Do not print cargo log messages

tests/testsuite/cargo_new/help/stdout.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Options:
1212
--bin Use a binary (application) template [default]
1313
--lib Use a library template
1414
--edition <YEAR> Edition to set for the crate generated [possible values: 2015, 2018,
15-
2021]
15+
2021, 2024]
1616
--name <NAME> Set the resulting package name, defaults to the directory name
1717
--registry <REGISTRY> Registry to use
1818
-q, --quiet Do not print cargo log messages

tests/testsuite/package.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ Caused by:
13591359
failed to parse the `edition` key
13601360
13611361
Caused by:
1362-
supported edition values are `2015`, `2018`, or `2021`, but `chicken` is unknown
1362+
supported edition values are `2015`, `2018`, `2021`, or `2024`, but `chicken` is unknown
13631363
"
13641364
.to_string(),
13651365
)
@@ -1391,7 +1391,7 @@ Caused by:
13911391
failed to parse the `edition` key
13921392
13931393
Caused by:
1394-
this version of Cargo is older than the `2038` edition, and only supports `2015`, `2018`, and `2021` editions.
1394+
this version of Cargo is older than the `2038` edition, and only supports `2015`, `2018`, `2021`, and `2024` editions.
13951395
"
13961396
.to_string(),
13971397
)

0 commit comments

Comments
 (0)