Use Edition methods a bit more

This commit is contained in:
Maybe Waffle 2023-01-31 09:50:56 +00:00
parent dc3e59cb3f
commit fd5774a4d7
5 changed files with 11 additions and 12 deletions

View file

@ -131,7 +131,7 @@ pub fn print_crate<'a>(
// Currently, in Rust 2018 we don't have `extern crate std;` at the crate // Currently, in Rust 2018 we don't have `extern crate std;` at the crate
// root, so this is not needed, and actually breaks things. // root, so this is not needed, and actually breaks things.
if edition == Edition::Edition2015 { if edition.rust_2015() {
// `#![no_std]` // `#![no_std]`
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP); let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
s.print_attribute(&fake_attr); s.print_attribute(&fake_attr);

View file

@ -1717,7 +1717,7 @@ impl<'a> Resolver<'a> {
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
)), )),
) )
} else if self.session.edition() == Edition::Edition2015 { } else if self.session.edition().rust_2015() {
( (
format!("maybe a missing crate `{ident}`?"), format!("maybe a missing crate `{ident}`?"),
Some(( Some((

View file

@ -7,7 +7,6 @@ use rustc_middle::ty;
use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
use rustc_session::lint::BuiltinLintDiagnostics; use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::edition::Edition;
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext}; use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
use rustc_span::symbol::{kw, Ident}; use rustc_span::symbol::{kw, Ident};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -86,7 +85,7 @@ impl<'a> Resolver<'a> {
// 4c. Standard library prelude (de-facto closed, controlled). // 4c. Standard library prelude (de-facto closed, controlled).
// 6. Language prelude: builtin attributes (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 { let (ns, macro_kind, is_absolute_path) = match scope_set {
ScopeSet::All(ns, _) => (ns, None, false), ScopeSet::All(ns, _) => (ns, None, false),
ScopeSet::AbsolutePath(ns) => (ns, None, true), ScopeSet::AbsolutePath(ns) => (ns, None, true),

View file

@ -900,22 +900,22 @@ impl Session {
} }
pub fn rust_2015(&self) -> bool { 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? /// Are we allowed to use features from the Rust 2018 edition?
pub fn rust_2018(&self) -> bool { pub fn rust_2018(&self) -> bool {
self.edition() >= Edition::Edition2018 self.edition().rust_2018()
} }
/// Are we allowed to use features from the Rust 2021 edition? /// Are we allowed to use features from the Rust 2021 edition?
pub fn rust_2021(&self) -> bool { 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? /// Are we allowed to use features from the Rust 2024 edition?
pub fn rust_2024(&self) -> bool { 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. /// Returns `true` if we cannot skip the PLT for shared library calls.

View file

@ -706,22 +706,22 @@ impl Span {
#[inline] #[inline]
pub fn rust_2015(self) -> bool { pub fn rust_2015(self) -> bool {
self.edition() == edition::Edition::Edition2015 self.edition().rust_2015()
} }
#[inline] #[inline]
pub fn rust_2018(self) -> bool { pub fn rust_2018(self) -> bool {
self.edition() >= edition::Edition::Edition2018 self.edition().rust_2018()
} }
#[inline] #[inline]
pub fn rust_2021(self) -> bool { pub fn rust_2021(self) -> bool {
self.edition() >= edition::Edition::Edition2021 self.edition().rust_2021()
} }
#[inline] #[inline]
pub fn rust_2024(self) -> bool { pub fn rust_2024(self) -> bool {
self.edition() >= edition::Edition::Edition2024 self.edition().rust_2024()
} }
/// Returns the source callee. /// Returns the source callee.