about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2024-09-29 22:11:59 +0000
committerLukas Markeffsky <@>2024-09-30 20:55:37 +0000
commit19252bde65c8587bcf43ae464d49c56791696afa (patch)
treee12bb023d8b9ec7397ac633ca7660a282e5527f7
parent63a0bdd5622eaf6b9524702f055bb4525acfc9f2 (diff)
downloadrust-19252bde65c8587bcf43ae464d49c56791696afa.tar.gz
rust-19252bde65c8587bcf43ae464d49c56791696afa.zip
add `stable_since` convenience
-rw-r--r--compiler/rustc_attr/src/builtin.rs10
-rw-r--r--src/librustdoc/clean/types.rs5
2 files changed, 11 insertions, 4 deletions
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs
index 762ebc47ca9..28d73fbe9f3 100644
--- a/compiler/rustc_attr/src/builtin.rs
+++ b/compiler/rustc_attr/src/builtin.rs
@@ -80,6 +80,10 @@ impl Stability {
     pub fn is_stable(&self) -> bool {
         self.level.is_stable()
     }
+
+    pub fn stable_since(&self) -> Option<StableSince> {
+        self.level.stable_since()
+    }
 }
 
 /// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
@@ -170,6 +174,12 @@ impl StabilityLevel {
     pub fn is_stable(&self) -> bool {
         matches!(self, StabilityLevel::Stable { .. })
     }
+    pub fn stable_since(&self) -> Option<StableSince> {
+        match *self {
+            StabilityLevel::Stable { since, .. } => Some(since),
+            StabilityLevel::Unstable { .. } => None,
+        }
+    }
 }
 
 #[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index b9c5e8e787b..2fccdb923d4 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -638,10 +638,7 @@ impl Item {
     }
 
     pub(crate) fn stable_since(&self, tcx: TyCtxt<'_>) -> Option<StableSince> {
-        match self.stability(tcx)?.level {
-            StabilityLevel::Stable { since, .. } => Some(since),
-            StabilityLevel::Unstable { .. } => None,
-        }
+        self.stability(tcx).and_then(|stability| stability.stable_since())
     }
 
     pub(crate) fn is_non_exhaustive(&self) -> bool {