mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
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.
This commit is contained in:
commit
20bf34f8c5
@ -722,7 +722,7 @@ impl NonterminalKind {
|
||||
Edition::Edition2015 | Edition::Edition2018 => {
|
||||
NonterminalKind::PatParam { inferred: true }
|
||||
}
|
||||
Edition::Edition2021 => NonterminalKind::PatWithOr,
|
||||
Edition::Edition2021 | Edition::Edition2024 => NonterminalKind::PatWithOr,
|
||||
},
|
||||
sym::pat_param => NonterminalKind::PatParam { inferred: false },
|
||||
sym::expr => NonterminalKind::Expr,
|
||||
|
@ -70,6 +70,7 @@ pub fn inject(
|
||||
Edition2015 => sym::rust_2015,
|
||||
Edition2018 => sym::rust_2018,
|
||||
Edition2021 => sym::rust_2021,
|
||||
Edition2024 => sym::rust_2024,
|
||||
}])
|
||||
.map(|&symbol| Ident::new(symbol, span))
|
||||
.collect();
|
||||
|
@ -1114,7 +1114,7 @@ fn check_matcher_core<'tt>(
|
||||
err.span_label(sp, format!("not allowed after `{}` fragments", kind));
|
||||
|
||||
if kind == NonterminalKind::PatWithOr
|
||||
&& sess.edition == Edition::Edition2021
|
||||
&& sess.edition.rust_2021()
|
||||
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
|
||||
{
|
||||
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
|
||||
|
@ -991,6 +991,11 @@ impl Session {
|
||||
self.opts.edition >= Edition::Edition2021
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2024 edition?
|
||||
pub fn rust_2024(&self) -> bool {
|
||||
self.opts.edition >= Edition::Edition2024
|
||||
}
|
||||
|
||||
pub fn edition(&self) -> Edition {
|
||||
self.opts.edition
|
||||
}
|
||||
|
@ -22,13 +22,15 @@ pub enum Edition {
|
||||
Edition2018,
|
||||
/// The 2021 edition
|
||||
Edition2021,
|
||||
/// The 2024 edition
|
||||
Edition2024,
|
||||
}
|
||||
|
||||
// Must be in order from oldest to newest.
|
||||
pub const ALL_EDITIONS: &[Edition] =
|
||||
&[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021];
|
||||
&[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024];
|
||||
|
||||
pub const EDITION_NAME_LIST: &str = "2015|2018|2021";
|
||||
pub const EDITION_NAME_LIST: &str = "2015|2018|2021|2024";
|
||||
|
||||
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
|
||||
|
||||
@ -40,6 +42,7 @@ impl fmt::Display for Edition {
|
||||
Edition::Edition2015 => "2015",
|
||||
Edition::Edition2018 => "2018",
|
||||
Edition::Edition2021 => "2021",
|
||||
Edition::Edition2024 => "2024",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
@ -51,6 +54,7 @@ impl Edition {
|
||||
Edition::Edition2015 => "rust_2015_compatibility",
|
||||
Edition::Edition2018 => "rust_2018_compatibility",
|
||||
Edition::Edition2021 => "rust_2021_compatibility",
|
||||
Edition::Edition2024 => "rust_2024_compatibility",
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +63,7 @@ impl Edition {
|
||||
Edition::Edition2015 => sym::rust_2015_preview,
|
||||
Edition::Edition2018 => sym::rust_2018_preview,
|
||||
Edition::Edition2021 => sym::rust_2021_preview,
|
||||
Edition::Edition2024 => sym::rust_2024_preview,
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,8 +72,28 @@ impl Edition {
|
||||
Edition::Edition2015 => true,
|
||||
Edition::Edition2018 => true,
|
||||
Edition::Edition2021 => true,
|
||||
Edition::Edition2024 => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rust_2015(&self) -> bool {
|
||||
*self == Edition::Edition2015
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2018 edition?
|
||||
pub fn rust_2018(&self) -> bool {
|
||||
*self >= Edition::Edition2018
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2021 edition?
|
||||
pub fn rust_2021(&self) -> bool {
|
||||
*self >= Edition::Edition2021
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2024 edition?
|
||||
pub fn rust_2024(&self) -> bool {
|
||||
*self >= Edition::Edition2024
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Edition {
|
||||
@ -78,6 +103,7 @@ impl FromStr for Edition {
|
||||
"2015" => Ok(Edition::Edition2015),
|
||||
"2018" => Ok(Edition::Edition2018),
|
||||
"2021" => Ok(Edition::Edition2021),
|
||||
"2024" => Ok(Edition::Edition2024),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
@ -684,6 +684,11 @@ impl Span {
|
||||
self.edition() >= edition::Edition::Edition2021
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rust_2024(self) -> bool {
|
||||
self.edition() >= edition::Edition::Edition2024
|
||||
}
|
||||
|
||||
/// Returns the source callee.
|
||||
///
|
||||
/// Returns `None` if the supplied span has no expansion trace,
|
||||
|
@ -1149,6 +1149,8 @@ symbols! {
|
||||
rust_2018_preview,
|
||||
rust_2021,
|
||||
rust_2021_preview,
|
||||
rust_2024,
|
||||
rust_2024_preview,
|
||||
rust_begin_unwind,
|
||||
rust_eh_catch_typeinfo,
|
||||
rust_eh_personality,
|
||||
|
@ -45,3 +45,13 @@ pub mod rust_2021 {
|
||||
#[doc(no_inline)]
|
||||
pub use crate::convert::{TryFrom, TryInto};
|
||||
}
|
||||
|
||||
/// The 2024 edition of the core prelude.
|
||||
///
|
||||
/// See the [module-level documentation](self) for more.
|
||||
#[unstable(feature = "prelude_2024", issue = "none")]
|
||||
pub mod rust_2024 {
|
||||
#[unstable(feature = "prelude_2024", issue = "none")]
|
||||
#[doc(no_inline)]
|
||||
pub use super::rust_2021::*;
|
||||
}
|
||||
|
@ -279,6 +279,7 @@
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(panic_internals)]
|
||||
#![feature(portable_simd)]
|
||||
#![feature(prelude_2024)]
|
||||
#![feature(ptr_as_uninit)]
|
||||
#![feature(raw_os_nonzero)]
|
||||
#![feature(slice_internals)]
|
||||
|
@ -132,3 +132,17 @@ pub mod rust_2021 {
|
||||
#[doc(no_inline)]
|
||||
pub use core::prelude::rust_2021::*;
|
||||
}
|
||||
|
||||
/// The 2024 version of the prelude of The Rust Standard Library.
|
||||
///
|
||||
/// See the [module-level documentation](self) for more.
|
||||
#[unstable(feature = "prelude_2024", issue = "none")]
|
||||
pub mod rust_2024 {
|
||||
#[unstable(feature = "prelude_2024", issue = "none")]
|
||||
#[doc(no_inline)]
|
||||
pub use super::v1::*;
|
||||
|
||||
#[unstable(feature = "prelude_2024", issue = "none")]
|
||||
#[doc(no_inline)]
|
||||
pub use core::prelude::rust_2024::*;
|
||||
}
|
||||
|
@ -1,5 +1,12 @@
|
||||
// run-pass
|
||||
// revisions: e2015 e2018 e2021 e2024
|
||||
|
||||
pub fn main() {
|
||||
println!("hello, world");
|
||||
//[e2018] edition:2018
|
||||
//[e2021] edition:2021
|
||||
//[e2024] edition:2024
|
||||
|
||||
//[e2024] compile-flags: -Zunstable-options
|
||||
|
||||
fn main() {
|
||||
println!("hello");
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
// run-pass
|
||||
// edition:2021
|
||||
|
||||
fn main() {
|
||||
println!("hello, 2021");
|
||||
}
|
@ -693,6 +693,7 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
|
||||
"2015" => Ok(Edition::Edition2015),
|
||||
"2018" => Ok(Edition::Edition2018),
|
||||
"2021" => Ok(Edition::Edition2021),
|
||||
"2024" => Ok(Edition::Edition2024),
|
||||
_ => Err(format_err!("Invalid value for `--edition`")),
|
||||
}
|
||||
}
|
||||
|
@ -423,6 +423,10 @@ pub enum Edition {
|
||||
#[doc_hint = "2021"]
|
||||
/// Edition 2021.
|
||||
Edition2021,
|
||||
#[value = "2024"]
|
||||
#[doc_hint = "2024"]
|
||||
/// Edition 2024.
|
||||
Edition2024,
|
||||
}
|
||||
|
||||
impl Default for Edition {
|
||||
@ -437,6 +441,7 @@ impl From<Edition> for rustc_span::edition::Edition {
|
||||
Edition::Edition2015 => Self::Edition2015,
|
||||
Edition::Edition2018 => Self::Edition2018,
|
||||
Edition::Edition2021 => Self::Edition2021,
|
||||
Edition::Edition2024 => Self::Edition2024,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user