Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create (unstable) 2024 edition #94461

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

&& sess.edition.rust_2021()
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
{
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 28 additions & 2 deletions compiler/rustc_span/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +42,7 @@ impl fmt::Display for Edition {
Edition::Edition2015 => "2015",
Edition::Edition2018 => "2018",
Edition::Edition2021 => "2021",
Edition::Edition2024 => "2024",
};
write!(f, "{}", s)
}
Expand All @@ -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",
}
}

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

Expand All @@ -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 {
Expand All @@ -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(()),
}
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions library/core/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
}
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
14 changes: 14 additions & 0 deletions library/std/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
}
11 changes: 9 additions & 2 deletions src/test/ui/hello.rs
Original file line number Diff line number Diff line change
@@ -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");
}
6 changes: 0 additions & 6 deletions src/test/ui/hello2021.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/tools/rustfmt/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`")),
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/tools/rustfmt/src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down