Skip to content

Commit 20bf34f

Browse files
authored
Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelix
Create (unstable) 2024 edition [On Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Deprecating.20macro.20scoping.20shenanigans/near/272860652), there was a small aside regarding creating the 2024 edition now as opposed to later. There was a reasonable amount of support and no stated opposition. This change creates the 2024 edition in the compiler and creates a prelude for the 2024 edition. There is no current difference between the 2021 and 2024 editions. Cargo and other tools will need to be updated separately, as it's not in the same repository. This change permits the vast majority of work towards the next edition to proceed _now_ instead of waiting until 2024. For sanity purposes, I've merged the "hello" UI tests into a single file with multiple revisions. Otherwise we'd end up with a file per edition, despite them being essentially identical. ````@rustbot```` label +T-lang +S-waiting-on-review Not sure on the relevant team, to be honest.
2 parents 27e2d81 + 6b75406 commit 20bf34f

File tree

14 files changed

+83
-12
lines changed

14 files changed

+83
-12
lines changed

Diff for: compiler/rustc_ast/src/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ impl NonterminalKind {
722722
Edition::Edition2015 | Edition::Edition2018 => {
723723
NonterminalKind::PatParam { inferred: true }
724724
}
725-
Edition::Edition2021 => NonterminalKind::PatWithOr,
725+
Edition::Edition2021 | Edition::Edition2024 => NonterminalKind::PatWithOr,
726726
},
727727
sym::pat_param => NonterminalKind::PatParam { inferred: false },
728728
sym::expr => NonterminalKind::Expr,

Diff for: compiler/rustc_builtin_macros/src/standard_library_imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub fn inject(
7070
Edition2015 => sym::rust_2015,
7171
Edition2018 => sym::rust_2018,
7272
Edition2021 => sym::rust_2021,
73+
Edition2024 => sym::rust_2024,
7374
}])
7475
.map(|&symbol| Ident::new(symbol, span))
7576
.collect();

Diff for: compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ fn check_matcher_core<'tt>(
11141114
err.span_label(sp, format!("not allowed after `{}` fragments", kind));
11151115

11161116
if kind == NonterminalKind::PatWithOr
1117-
&& sess.edition == Edition::Edition2021
1117+
&& sess.edition.rust_2021()
11181118
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
11191119
{
11201120
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(

Diff for: compiler/rustc_session/src/session.rs

+5
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,11 @@ impl Session {
991991
self.opts.edition >= Edition::Edition2021
992992
}
993993

994+
/// Are we allowed to use features from the Rust 2024 edition?
995+
pub fn rust_2024(&self) -> bool {
996+
self.opts.edition >= Edition::Edition2024
997+
}
998+
994999
pub fn edition(&self) -> Edition {
9951000
self.opts.edition
9961001
}

Diff for: compiler/rustc_span/src/edition.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ pub enum Edition {
2222
Edition2018,
2323
/// The 2021 edition
2424
Edition2021,
25+
/// The 2024 edition
26+
Edition2024,
2527
}
2628

2729
// Must be in order from oldest to newest.
2830
pub const ALL_EDITIONS: &[Edition] =
29-
&[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021];
31+
&[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024];
3032

31-
pub const EDITION_NAME_LIST: &str = "2015|2018|2021";
33+
pub const EDITION_NAME_LIST: &str = "2015|2018|2021|2024";
3234

3335
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
3436

@@ -40,6 +42,7 @@ impl fmt::Display for Edition {
4042
Edition::Edition2015 => "2015",
4143
Edition::Edition2018 => "2018",
4244
Edition::Edition2021 => "2021",
45+
Edition::Edition2024 => "2024",
4346
};
4447
write!(f, "{}", s)
4548
}
@@ -51,6 +54,7 @@ impl Edition {
5154
Edition::Edition2015 => "rust_2015_compatibility",
5255
Edition::Edition2018 => "rust_2018_compatibility",
5356
Edition::Edition2021 => "rust_2021_compatibility",
57+
Edition::Edition2024 => "rust_2024_compatibility",
5458
}
5559
}
5660

@@ -59,6 +63,7 @@ impl Edition {
5963
Edition::Edition2015 => sym::rust_2015_preview,
6064
Edition::Edition2018 => sym::rust_2018_preview,
6165
Edition::Edition2021 => sym::rust_2021_preview,
66+
Edition::Edition2024 => sym::rust_2024_preview,
6267
}
6368
}
6469

@@ -67,8 +72,28 @@ impl Edition {
6772
Edition::Edition2015 => true,
6873
Edition::Edition2018 => true,
6974
Edition::Edition2021 => true,
75+
Edition::Edition2024 => false,
7076
}
7177
}
78+
79+
pub fn rust_2015(&self) -> bool {
80+
*self == Edition::Edition2015
81+
}
82+
83+
/// Are we allowed to use features from the Rust 2018 edition?
84+
pub fn rust_2018(&self) -> bool {
85+
*self >= Edition::Edition2018
86+
}
87+
88+
/// Are we allowed to use features from the Rust 2021 edition?
89+
pub fn rust_2021(&self) -> bool {
90+
*self >= Edition::Edition2021
91+
}
92+
93+
/// Are we allowed to use features from the Rust 2024 edition?
94+
pub fn rust_2024(&self) -> bool {
95+
*self >= Edition::Edition2024
96+
}
7297
}
7398

7499
impl FromStr for Edition {
@@ -78,6 +103,7 @@ impl FromStr for Edition {
78103
"2015" => Ok(Edition::Edition2015),
79104
"2018" => Ok(Edition::Edition2018),
80105
"2021" => Ok(Edition::Edition2021),
106+
"2024" => Ok(Edition::Edition2024),
81107
_ => Err(()),
82108
}
83109
}

Diff for: compiler/rustc_span/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,11 @@ impl Span {
684684
self.edition() >= edition::Edition::Edition2021
685685
}
686686

687+
#[inline]
688+
pub fn rust_2024(self) -> bool {
689+
self.edition() >= edition::Edition::Edition2024
690+
}
691+
687692
/// Returns the source callee.
688693
///
689694
/// Returns `None` if the supplied span has no expansion trace,

Diff for: compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,8 @@ symbols! {
11491149
rust_2018_preview,
11501150
rust_2021,
11511151
rust_2021_preview,
1152+
rust_2024,
1153+
rust_2024_preview,
11521154
rust_begin_unwind,
11531155
rust_eh_catch_typeinfo,
11541156
rust_eh_personality,

Diff for: library/core/src/prelude/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ pub mod rust_2021 {
4545
#[doc(no_inline)]
4646
pub use crate::convert::{TryFrom, TryInto};
4747
}
48+
49+
/// The 2024 edition of the core prelude.
50+
///
51+
/// See the [module-level documentation](self) for more.
52+
#[unstable(feature = "prelude_2024", issue = "none")]
53+
pub mod rust_2024 {
54+
#[unstable(feature = "prelude_2024", issue = "none")]
55+
#[doc(no_inline)]
56+
pub use super::rust_2021::*;
57+
}

Diff for: library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
#![feature(panic_info_message)]
280280
#![feature(panic_internals)]
281281
#![feature(portable_simd)]
282+
#![feature(prelude_2024)]
282283
#![feature(ptr_as_uninit)]
283284
#![feature(raw_os_nonzero)]
284285
#![feature(slice_internals)]

Diff for: library/std/src/prelude/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,17 @@ pub mod rust_2021 {
132132
#[doc(no_inline)]
133133
pub use core::prelude::rust_2021::*;
134134
}
135+
136+
/// The 2024 version of the prelude of The Rust Standard Library.
137+
///
138+
/// See the [module-level documentation](self) for more.
139+
#[unstable(feature = "prelude_2024", issue = "none")]
140+
pub mod rust_2024 {
141+
#[unstable(feature = "prelude_2024", issue = "none")]
142+
#[doc(no_inline)]
143+
pub use super::v1::*;
144+
145+
#[unstable(feature = "prelude_2024", issue = "none")]
146+
#[doc(no_inline)]
147+
pub use core::prelude::rust_2024::*;
148+
}

Diff for: src/test/ui/hello.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// run-pass
2+
// revisions: e2015 e2018 e2021 e2024
23

3-
pub fn main() {
4-
println!("hello, world");
4+
//[e2018] edition:2018
5+
//[e2021] edition:2021
6+
//[e2024] edition:2024
7+
8+
//[e2024] compile-flags: -Zunstable-options
9+
10+
fn main() {
11+
println!("hello");
512
}

Diff for: src/test/ui/hello2021.rs

-6
This file was deleted.

Diff for: src/tools/rustfmt/src/bin/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
693693
"2015" => Ok(Edition::Edition2015),
694694
"2018" => Ok(Edition::Edition2018),
695695
"2021" => Ok(Edition::Edition2021),
696+
"2024" => Ok(Edition::Edition2024),
696697
_ => Err(format_err!("Invalid value for `--edition`")),
697698
}
698699
}

Diff for: src/tools/rustfmt/src/config/options.rs

+5
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ pub enum Edition {
423423
#[doc_hint = "2021"]
424424
/// Edition 2021.
425425
Edition2021,
426+
#[value = "2024"]
427+
#[doc_hint = "2024"]
428+
/// Edition 2024.
429+
Edition2024,
426430
}
427431

428432
impl Default for Edition {
@@ -437,6 +441,7 @@ impl From<Edition> for rustc_span::edition::Edition {
437441
Edition::Edition2015 => Self::Edition2015,
438442
Edition::Edition2018 => Self::Edition2018,
439443
Edition::Edition2021 => Self::Edition2021,
444+
Edition::Edition2024 => Self::Edition2024,
440445
}
441446
}
442447
}

0 commit comments

Comments
 (0)