diff options
| author | David Tolnay <dtolnay@gmail.com> | 2023-10-30 08:53:21 -0700 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2023-10-30 15:41:18 -0700 |
| commit | b106167673c271940e1277cb27f6b75a58f66473 (patch) | |
| tree | e04214a9d9f25ff6b429a58c7b8c8f7fab1ed7f6 /compiler/rustc_attr/src | |
| parent | 1e10fe9eb67fabb97729c3faf4852121f1f608da (diff) | |
Add a DeprecatedSince::Err variant for versions that fail to parse
Diffstat (limited to 'compiler/rustc_attr/src')
| -rw-r--r-- | compiler/rustc_attr/src/builtin.rs | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 49c6b84a4a5..8ffd322b93f 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -13,7 +13,6 @@ use rustc_session::parse::{feature_err, ParseSess}; use rustc_session::{RustcVersion, Session}; use rustc_span::hygiene::Transparency; use rustc_span::{symbol::sym, symbol::Symbol, Span}; -use std::fmt::{self, Display}; use std::num::NonZeroU32; use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause}; @@ -736,12 +735,12 @@ pub enum DeprecatedSince { RustcVersion(RustcVersion), /// Deprecated in the future ("to be determined"). Future, - /// `feature(staged_api)` is off, or it's on but the deprecation version - /// cannot be parsed as a RustcVersion. In the latter case, an error has - /// already been emitted. In the former case, deprecation versions outside - /// the standard library are allowed to be arbitrary strings, for better or - /// worse. + /// `feature(staged_api)` is off. Deprecation versions outside the standard + /// library are allowed to be arbitrary strings, for better or worse. Symbol(Symbol), + /// Failed to parse a deprecation version. An error has already been + /// emitted. + Err, } impl Deprecation { @@ -754,18 +753,8 @@ impl Deprecation { Some(DeprecatedSince::Future) => false, // The `since` field doesn't have semantic purpose without `#![staged_api]`. Some(DeprecatedSince::Symbol(_)) => true, - // Assume deprecation is in effect if "since" field is missing. - None => true, - } - } -} - -impl Display for DeprecatedSince { - fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - DeprecatedSince::RustcVersion(since) => Display::fmt(since, formatter), - DeprecatedSince::Future => formatter.write_str("TBD"), - DeprecatedSince::Symbol(since) => Display::fmt(since, formatter), + // Assume deprecation is in effect if "since" field is absent or invalid. + None | Some(DeprecatedSince::Err) => true, } } } @@ -885,7 +874,7 @@ pub fn find_deprecation( Some(DeprecatedSince::RustcVersion(version)) } else { sess.emit_err(session_diagnostics::InvalidSince { span: attr.span }); - Some(DeprecatedSince::Symbol(since)) + Some(DeprecatedSince::Err) } } else if is_rustc { sess.emit_err(session_diagnostics::MissingSince { span: attr.span }); |
