Skip to content

Commit 6b75406

Browse files
committed
Create 2024 edition
1 parent 79f178b commit 6b75406

File tree

14 files changed

+83
-12
lines changed

14 files changed

+83
-12
lines changed

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,

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();

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ fn check_matcher_core(
10331033
err.span_label(sp, format!("not allowed after `{}` fragments", kind));
10341034

10351035
if kind == NonterminalKind::PatWithOr
1036-
&& sess.edition == Edition::Edition2021
1036+
&& sess.edition.rust_2021()
10371037
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
10381038
{
10391039
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(

compiler/rustc_session/src/session.rs

+5
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,11 @@ impl Session {
945945
self.opts.edition >= Edition::Edition2021
946946
}
947947

948+
/// Are we allowed to use features from the Rust 2024 edition?
949+
pub fn rust_2024(&self) -> bool {
950+
self.opts.edition >= Edition::Edition2024
951+
}
952+
948953
pub fn edition(&self) -> Edition {
949954
self.opts.edition
950955
}

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
}

compiler/rustc_span/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ impl Span {
698698
self.edition() >= edition::Edition::Edition2021
699699
}
700700

701+
#[inline]
702+
pub fn rust_2024(self) -> bool {
703+
self.edition() >= edition::Edition::Edition2024
704+
}
705+
701706
/// Returns the source callee.
702707
///
703708
/// Returns `None` if the supplied span has no expansion trace,

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,8 @@ symbols! {
11451145
rust_2018_preview,
11461146
rust_2021,
11471147
rust_2021_preview,
1148+
rust_2024,
1149+
rust_2024_preview,
11481150
rust_begin_unwind,
11491151
rust_eh_catch_typeinfo,
11501152
rust_eh_personality,

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+
}

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)]

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+
}

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
}

src/test/ui/hello2021.rs

-6
This file was deleted.

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
}

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)