Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r--crates/hir/src/lib.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 24faa127e4..4190707884 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -2165,6 +2165,16 @@ impl AsAssocItem for ModuleDef {
}
}
}
+impl AsAssocItem for DefWithBody {
+ fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
+ match self {
+ DefWithBody::Function(it) => it.as_assoc_item(db),
+ DefWithBody::Const(it) => it.as_assoc_item(db),
+ DefWithBody::Static(_) | DefWithBody::Variant(_) => None,
+ }
+ }
+}
+
fn as_assoc_item<ID, DEF, CTOR, AST>(db: &dyn HirDatabase, ctor: CTOR, id: ID) -> Option<AssocItem>
where
ID: Lookup<Data = AssocItemLoc<AST>>,
@@ -2560,6 +2570,14 @@ impl GenericParam {
GenericParam::LifetimeParam(it) => it.name(db),
}
}
+
+ pub fn parent(self) -> GenericDef {
+ match self {
+ GenericParam::TypeParam(it) => it.id.parent().into(),
+ GenericParam::ConstParam(it) => it.id.parent().into(),
+ GenericParam::LifetimeParam(it) => it.id.parent.into(),
+ }
+ }
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]