Skip to content

Commit

Permalink
Add Type::lifetimes to make getting lifetimes out of Type easier (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
QnnOkabayashi authored Jan 17, 2024
1 parent 98ac7ad commit f4188b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/hir/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ impl<Kind: LifetimeKind> Lifetimes<Kind> {
pub(super) fn lifetimes(&self) -> impl Iterator<Item = MaybeStatic<Lifetime<Kind>>> + '_ {
self.indices.iter().copied()
}

pub(super) fn as_slice(&self) -> &[MaybeStatic<Lifetime<Kind>>] {
self.indices.as_slice()
}
}

impl TypeLifetime {
Expand Down
10 changes: 10 additions & 0 deletions core/src/hir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ impl Type {
Type::Primitive(_) | Type::Enum(_) => (0, 0),
}
}

#[allow(unused)] // wip lifetimes (#406)
pub(super) fn lifetimes(&self) -> &[MaybeStatic<TypeLifetime>] {
match self {
Type::Opaque(opaque) => opaque.lifetimes.as_slice(),
Type::Struct(struct_) => struct_.lifetimes.as_slice(),
Type::Slice(slice) => std::slice::from_ref(slice.lifetime()),
_ => &[],
}
}
}

impl SelfType {
Expand Down

0 comments on commit f4188b3

Please sign in to comment.