Skip to content

Commit 544b73b

Browse files
Rollup merge of #107508 - WaffleLapkin:uneq'15, r=oli-obk
`Edition` micro refactor r? `@oli-obk`
2 parents a354532 + ef6b583 commit 544b73b

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn print_crate<'a>(
131131

132132
// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
133133
// root, so this is not needed, and actually breaks things.
134-
if edition == Edition::Edition2015 {
134+
if edition.rust_2015() {
135135
// `#![no_std]`
136136
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
137137
s.print_attribute(&fake_attr);

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ impl<'a> Resolver<'a> {
17171717
Applicability::MaybeIncorrect,
17181718
)),
17191719
)
1720-
} else if self.session.edition() == Edition::Edition2015 {
1720+
} else if self.session.rust_2015() {
17211721
(
17221722
format!("maybe a missing crate `{ident}`?"),
17231723
Some((

compiler/rustc_resolve/src/ident.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_middle::ty;
77
use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
88
use rustc_session::lint::BuiltinLintDiagnostics;
99
use rustc_span::def_id::LocalDefId;
10-
use rustc_span::edition::Edition;
1110
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
1211
use rustc_span::symbol::{kw, Ident};
1312
use rustc_span::{Span, DUMMY_SP};
@@ -86,7 +85,7 @@ impl<'a> Resolver<'a> {
8685
// 4c. Standard library prelude (de-facto closed, controlled).
8786
// 6. Language prelude: builtin attributes (closed, controlled).
8887

89-
let rust_2015 = ctxt.edition() == Edition::Edition2015;
88+
let rust_2015 = ctxt.edition().rust_2015();
9089
let (ns, macro_kind, is_absolute_path) = match scope_set {
9190
ScopeSet::All(ns, _) => (ns, None, false),
9291
ScopeSet::AbsolutePath(ns) => (ns, None, true),

compiler/rustc_session/src/session.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -899,23 +899,24 @@ impl Session {
899899
ret
900900
}
901901

902+
/// Is this edition 2015?
902903
pub fn rust_2015(&self) -> bool {
903-
self.edition() == Edition::Edition2015
904+
self.edition().rust_2015()
904905
}
905906

906907
/// Are we allowed to use features from the Rust 2018 edition?
907908
pub fn rust_2018(&self) -> bool {
908-
self.edition() >= Edition::Edition2018
909+
self.edition().rust_2018()
909910
}
910911

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

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

921922
/// Returns `true` if we cannot skip the PLT for shared library calls.

compiler/rustc_span/src/edition.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -49,50 +49,51 @@ impl fmt::Display for Edition {
4949
}
5050

5151
impl Edition {
52-
pub fn lint_name(&self) -> &'static str {
53-
match *self {
52+
pub fn lint_name(self) -> &'static str {
53+
match self {
5454
Edition::Edition2015 => "rust_2015_compatibility",
5555
Edition::Edition2018 => "rust_2018_compatibility",
5656
Edition::Edition2021 => "rust_2021_compatibility",
5757
Edition::Edition2024 => "rust_2024_compatibility",
5858
}
5959
}
6060

61-
pub fn feature_name(&self) -> Symbol {
62-
match *self {
61+
pub fn feature_name(self) -> Symbol {
62+
match self {
6363
Edition::Edition2015 => sym::rust_2015_preview,
6464
Edition::Edition2018 => sym::rust_2018_preview,
6565
Edition::Edition2021 => sym::rust_2021_preview,
6666
Edition::Edition2024 => sym::rust_2024_preview,
6767
}
6868
}
6969

70-
pub fn is_stable(&self) -> bool {
71-
match *self {
70+
pub fn is_stable(self) -> bool {
71+
match self {
7272
Edition::Edition2015 => true,
7373
Edition::Edition2018 => true,
7474
Edition::Edition2021 => true,
7575
Edition::Edition2024 => false,
7676
}
7777
}
7878

79-
pub fn rust_2015(&self) -> bool {
80-
*self == Edition::Edition2015
79+
/// Is this edition 2015?
80+
pub fn rust_2015(self) -> bool {
81+
self == Edition::Edition2015
8182
}
8283

8384
/// Are we allowed to use features from the Rust 2018 edition?
84-
pub fn rust_2018(&self) -> bool {
85-
*self >= Edition::Edition2018
85+
pub fn rust_2018(self) -> bool {
86+
self >= Edition::Edition2018
8687
}
8788

8889
/// Are we allowed to use features from the Rust 2021 edition?
89-
pub fn rust_2021(&self) -> bool {
90-
*self >= Edition::Edition2021
90+
pub fn rust_2021(self) -> bool {
91+
self >= Edition::Edition2021
9192
}
9293

9394
/// Are we allowed to use features from the Rust 2024 edition?
94-
pub fn rust_2024(&self) -> bool {
95-
*self >= Edition::Edition2024
95+
pub fn rust_2024(self) -> bool {
96+
self >= Edition::Edition2024
9697
}
9798
}
9899

compiler/rustc_span/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -706,22 +706,22 @@ impl Span {
706706

707707
#[inline]
708708
pub fn rust_2015(self) -> bool {
709-
self.edition() == edition::Edition::Edition2015
709+
self.edition().rust_2015()
710710
}
711711

712712
#[inline]
713713
pub fn rust_2018(self) -> bool {
714-
self.edition() >= edition::Edition::Edition2018
714+
self.edition().rust_2018()
715715
}
716716

717717
#[inline]
718718
pub fn rust_2021(self) -> bool {
719-
self.edition() >= edition::Edition::Edition2021
719+
self.edition().rust_2021()
720720
}
721721

722722
#[inline]
723723
pub fn rust_2024(self) -> bool {
724-
self.edition() >= edition::Edition::Edition2024
724+
self.edition().rust_2024()
725725
}
726726

727727
/// Returns the source callee.

0 commit comments

Comments
 (0)