diff options
author | Lukas Markeffsky <@> | 2024-09-29 22:11:59 +0000 |
---|---|---|
committer | Lukas Markeffsky <@> | 2024-09-30 20:55:37 +0000 |
commit | 19252bde65c8587bcf43ae464d49c56791696afa (patch) | |
tree | e12bb023d8b9ec7397ac633ca7660a282e5527f7 | |
parent | 63a0bdd5622eaf6b9524702f055bb4525acfc9f2 (diff) |
add `stable_since` convenience
-rw-r--r-- | compiler/rustc_attr/src/builtin.rs | 10 | ||||
-rw-r--r-- | src/librustdoc/clean/types.rs | 5 |
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 { |