From 1e10fe9eb67fabb97729c3faf4852121f1f608da Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 30 Oct 2023 09:00:13 -0700 Subject: Move deprecation_in_effect to inherent method on Deprecation --- compiler/rustc_attr/src/builtin.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'compiler/rustc_attr/src') diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 62709ef4db9..49c6b84a4a5 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -744,6 +744,22 @@ pub enum DeprecatedSince { Symbol(Symbol), } +impl Deprecation { + /// Whether an item marked with #[deprecated(since = "X")] is currently + /// deprecated (i.e., whether X is not greater than the current rustc + /// version). + pub fn is_in_effect(&self) -> bool { + match self.since { + Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT, + 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 { -- cgit 1.4.1-3-g733a5