Skip to content

Commit 5cc7565

Browse files
committed
span: add a "next" edition
It's hard to implement edition migrations without having a perma-unstable "next" edition to target.
1 parent ad27045 commit 5cc7565

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub fn inject(
6060
Edition2018 => sym::rust_2018,
6161
Edition2021 => sym::rust_2021,
6262
Edition2024 => sym::rust_2024,
63+
EditionNext => sym::rust_next,
6364
}])
6465
.map(|&symbol| Ident::new(symbol, span))
6566
.collect();

compiler/rustc_span/src/edition.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ pub enum Edition {
2323
Edition2021,
2424
/// The 2024 edition
2525
Edition2024,
26+
/// The next edition - this variant will always exist and features associated with next will be
27+
/// moved to the next 20XX edition when it is established. This allows edition changes to
28+
/// be implemented before the next edition is planned.
29+
EditionNext,
2630
}
2731

2832
// Must be in order from oldest to newest.
29-
pub const ALL_EDITIONS: &[Edition] =
30-
&[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024];
33+
pub const ALL_EDITIONS: &[Edition] = &[
34+
Edition::Edition2015,
35+
Edition::Edition2018,
36+
Edition::Edition2021,
37+
Edition::Edition2024,
38+
Edition::EditionNext,
39+
];
3140

3241
pub const EDITION_NAME_LIST: &str = "2015|2018|2021|2024";
3342

@@ -42,6 +51,7 @@ impl fmt::Display for Edition {
4251
Edition::Edition2018 => "2018",
4352
Edition::Edition2021 => "2021",
4453
Edition::Edition2024 => "2024",
54+
Edition::EditionNext => "next",
4555
};
4656
write!(f, "{s}")
4757
}
@@ -54,6 +64,7 @@ impl Edition {
5464
Edition::Edition2018 => "rust_2018_compatibility",
5565
Edition::Edition2021 => "rust_2021_compatibility",
5666
Edition::Edition2024 => "rust_2024_compatibility",
67+
Edition::EditionNext => "edition_next_compatibility",
5768
}
5869
}
5970

@@ -63,6 +74,7 @@ impl Edition {
6374
Edition::Edition2018 => true,
6475
Edition::Edition2021 => true,
6576
Edition::Edition2024 => true,
77+
Edition::EditionNext => false,
6678
}
6779
}
6880

@@ -85,6 +97,11 @@ impl Edition {
8597
pub fn at_least_rust_2024(self) -> bool {
8698
self >= Edition::Edition2024
8799
}
100+
101+
/// Are we allowed to use features from the next edition?
102+
pub fn at_least_edition_next(self) -> bool {
103+
self >= Edition::EditionNext
104+
}
88105
}
89106

90107
impl FromStr for Edition {
@@ -95,6 +112,7 @@ impl FromStr for Edition {
95112
"2018" => Ok(Edition::Edition2018),
96113
"2021" => Ok(Edition::Edition2021),
97114
"2024" => Ok(Edition::Edition2024),
115+
"next" => Ok(Edition::EditionNext),
98116
_ => Err(()),
99117
}
100118
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ symbols! {
17121712
rust_eh_catch_typeinfo,
17131713
rust_eh_personality,
17141714
rust_logo,
1715+
rust_next,
17151716
rust_out,
17161717
rustc,
17171718
rustc_abi,

library/core/src/prelude/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@ pub mod rust_2024 {
7070
#[doc(no_inline)]
7171
pub use crate::future::{Future, IntoFuture};
7272
}
73+
74+
/// The Next version of the core prelude.
75+
///
76+
/// See the [module-level documentation](self) for more.
77+
#[unstable(feature = "prelude_next", issue = "none")]
78+
pub mod rust_next {
79+
#[stable(feature = "rust1", since = "1.0.0")]
80+
#[doc(no_inline)]
81+
pub use super::v1::*;
82+
83+
#[stable(feature = "prelude_2021", since = "1.55.0")]
84+
#[doc(no_inline)]
85+
pub use crate::iter::FromIterator;
86+
87+
#[stable(feature = "prelude_2021", since = "1.55.0")]
88+
#[doc(no_inline)]
89+
pub use crate::convert::{TryFrom, TryInto};
90+
91+
#[stable(feature = "prelude_2024", since = "1.85.0")]
92+
#[doc(no_inline)]
93+
pub use crate::future::{Future, IntoFuture};
94+
}

library/std/src/prelude/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,17 @@ pub mod rust_2024 {
160160
#[doc(no_inline)]
161161
pub use core::prelude::rust_2024::*;
162162
}
163+
164+
/// The Next version of the prelude of The Rust Standard Library.
165+
///
166+
/// See the [module-level documentation](self) for more.
167+
#[unstable(feature = "prelude_next", issue = "none")]
168+
pub mod rust_next {
169+
#[stable(feature = "rust1", since = "1.0.0")]
170+
#[doc(no_inline)]
171+
pub use super::v1::*;
172+
173+
#[unstable(feature = "prelude_next", issue = "none")]
174+
#[doc(no_inline)]
175+
pub use core::prelude::rust_next::*;
176+
}

0 commit comments

Comments
 (0)