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

Edition micro refactor #107508

Merged
merged 4 commits into from
Feb 1, 2023
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_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn print_crate<'a>(

// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
// root, so this is not needed, and actually breaks things.
if edition == Edition::Edition2015 {
if edition.rust_2015() {
// `#![no_std]`
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
s.print_attribute(&fake_attr);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ impl<'a> Resolver<'a> {
Applicability::MaybeIncorrect,
)),
)
} else if self.session.edition() == Edition::Edition2015 {
} else if self.session.rust_2015() {
(
format!("maybe a missing crate `{ident}`?"),
Some((
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc_middle::ty;
use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_span::def_id::LocalDefId;
use rustc_span::edition::Edition;
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
use rustc_span::symbol::{kw, Ident};
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -86,7 +85,7 @@ impl<'a> Resolver<'a> {
// 4c. Standard library prelude (de-facto closed, controlled).
// 6. Language prelude: builtin attributes (closed, controlled).

let rust_2015 = ctxt.edition() == Edition::Edition2015;
let rust_2015 = ctxt.edition().rust_2015();
let (ns, macro_kind, is_absolute_path) = match scope_set {
ScopeSet::All(ns, _) => (ns, None, false),
ScopeSet::AbsolutePath(ns) => (ns, None, true),
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,23 +899,24 @@ impl Session {
ret
}

/// Is this edition 2015?
pub fn rust_2015(&self) -> bool {
self.edition() == Edition::Edition2015
self.edition().rust_2015()
}

/// Are we allowed to use features from the Rust 2018 edition?
pub fn rust_2018(&self) -> bool {
self.edition() >= Edition::Edition2018
self.edition().rust_2018()
}
Comment on lines +902 to 910
Copy link
Member

Choose a reason for hiding this comment

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

Wait, so rust_2015 is edition == 2015, but rust_2018 is edition >= 2018? That's a bit confusing IMO

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could rename rust_2015.. or rename all the subsequent ones to at_least_rust_2018? idk


/// Are we allowed to use features from the Rust 2021 edition?
pub fn rust_2021(&self) -> bool {
self.edition() >= Edition::Edition2021
self.edition().rust_2021()
}

/// Are we allowed to use features from the Rust 2024 edition?
pub fn rust_2024(&self) -> bool {
self.edition() >= Edition::Edition2024
self.edition().rust_2024()
}

/// Returns `true` if we cannot skip the PLT for shared library calls.
Expand Down
29 changes: 15 additions & 14 deletions compiler/rustc_span/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,50 +49,51 @@ impl fmt::Display for Edition {
}

impl Edition {
pub fn lint_name(&self) -> &'static str {
match *self {
pub fn lint_name(self) -> &'static str {
match self {
Edition::Edition2015 => "rust_2015_compatibility",
Edition::Edition2018 => "rust_2018_compatibility",
Edition::Edition2021 => "rust_2021_compatibility",
Edition::Edition2024 => "rust_2024_compatibility",
}
}

pub fn feature_name(&self) -> Symbol {
match *self {
pub fn feature_name(self) -> Symbol {
match self {
Edition::Edition2015 => sym::rust_2015_preview,
Edition::Edition2018 => sym::rust_2018_preview,
Edition::Edition2021 => sym::rust_2021_preview,
Edition::Edition2024 => sym::rust_2024_preview,
}
}

pub fn is_stable(&self) -> bool {
match *self {
pub fn is_stable(self) -> bool {
match self {
Edition::Edition2015 => true,
Edition::Edition2018 => true,
Edition::Edition2021 => true,
Edition::Edition2024 => false,
}
}

pub fn rust_2015(&self) -> bool {
*self == Edition::Edition2015
/// Is this edition 2015?
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
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
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
pub fn rust_2024(self) -> bool {
self >= Edition::Edition2024
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,22 +706,22 @@ impl Span {

#[inline]
pub fn rust_2015(self) -> bool {
self.edition() == edition::Edition::Edition2015
self.edition().rust_2015()
}

#[inline]
pub fn rust_2018(self) -> bool {
self.edition() >= edition::Edition::Edition2018
self.edition().rust_2018()
}

#[inline]
pub fn rust_2021(self) -> bool {
self.edition() >= edition::Edition::Edition2021
self.edition().rust_2021()
}

#[inline]
pub fn rust_2024(self) -> bool {
self.edition() >= edition::Edition::Edition2024
self.edition().rust_2024()
}

/// Returns the source callee.
Expand Down