Create 2024 edition

This commit is contained in:
Jacob Pratt 2022-02-28 18:13:24 -05:00
parent 79f178b76e
commit 6b75406f5a
No known key found for this signature in database
GPG Key ID: B80E19E4662B5AA4
14 changed files with 83 additions and 12 deletions

View File

@ -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,

View File

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

View File

@ -1033,7 +1033,7 @@ fn check_matcher_core(
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(

View File

@ -945,6 +945,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
}

View File

@ -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(()),
}
}

View File

@ -698,6 +698,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,

View File

@ -1145,6 +1145,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,

View File

@ -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::*;
}

View File

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

View File

@ -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::*;
}

View File

@ -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");
}

View File

@ -1,6 +0,0 @@
// run-pass
// edition:2021
fn main() {
println!("hello, 2021");
}

View File

@ -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`")),
}
}

View File

@ -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,
}
}
}