Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/utils.rs')
-rw-r--r--crates/hir-ty/src/utils.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs
index afd4d1f271..77c5fd054d 100644
--- a/crates/hir-ty/src/utils.rs
+++ b/crates/hir-ty/src/utils.rs
@@ -262,7 +262,7 @@ impl<'a> ClosureSubst<'a> {
}
}
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub(crate) struct Generics {
def: GenericDefId,
pub(crate) params: Interned<GenericParams>,
@@ -274,6 +274,10 @@ impl Generics {
self.iter().map(|(id, _)| id)
}
+ pub(crate) fn def(&self) -> GenericDefId {
+ self.def
+ }
+
/// Iterator over types and const params of self, then parent.
pub(crate) fn iter<'a>(
&'a self,
@@ -450,6 +454,10 @@ impl Generics {
self.parent_generics.as_deref()
}
+ pub(crate) fn parent_or_self(&self) -> &Generics {
+ self.parent_generics.as_deref().unwrap_or(self)
+ }
+
/// Returns a Substitution that replaces each parameter by a bound variable.
pub(crate) fn bound_vars_subst(
&self,