Skip to content

Commit

Permalink
add stable_since convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Sep 30, 2024
1 parent 63a0bdd commit 19252bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)]
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 19252bd

Please sign in to comment.