Skip to content

Commit 19252bd

Browse files
author
Lukas Markeffsky
committed
add stable_since convenience
1 parent 63a0bdd commit 19252bd

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: compiler/rustc_attr/src/builtin.rs

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ impl Stability {
8080
pub fn is_stable(&self) -> bool {
8181
self.level.is_stable()
8282
}
83+
84+
pub fn stable_since(&self) -> Option<StableSince> {
85+
self.level.stable_since()
86+
}
8387
}
8488

8589
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
@@ -170,6 +174,12 @@ impl StabilityLevel {
170174
pub fn is_stable(&self) -> bool {
171175
matches!(self, StabilityLevel::Stable { .. })
172176
}
177+
pub fn stable_since(&self) -> Option<StableSince> {
178+
match *self {
179+
StabilityLevel::Stable { since, .. } => Some(since),
180+
StabilityLevel::Unstable { .. } => None,
181+
}
182+
}
173183
}
174184

175185
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]

Diff for: src/librustdoc/clean/types.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,7 @@ impl Item {
638638
}
639639

640640
pub(crate) fn stable_since(&self, tcx: TyCtxt<'_>) -> Option<StableSince> {
641-
match self.stability(tcx)?.level {
642-
StabilityLevel::Stable { since, .. } => Some(since),
643-
StabilityLevel::Unstable { .. } => None,
644-
}
641+
self.stability(tcx).and_then(|stability| stability.stable_since())
645642
}
646643

647644
pub(crate) fn is_non_exhaustive(&self) -> bool {

0 commit comments

Comments
 (0)