aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r--crates/hir/src/code_model.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 6cbf5cecf..2950f08b8 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -272,6 +272,15 @@ impl ModuleDef {
272 272
273 hir_ty::diagnostics::validate_module_item(db, module.id.krate, id, sink) 273 hir_ty::diagnostics::validate_module_item(db, module.id.krate, id, sink)
274 } 274 }
275
276 pub fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
277 match self {
278 ModuleDef::Function(f) => f.as_assoc_item(db),
279 ModuleDef::Const(c) => c.as_assoc_item(db),
280 ModuleDef::TypeAlias(t) => t.as_assoc_item(db),
281 _ => None,
282 }
283 }
275} 284}
276 285
277impl Module { 286impl Module {
@@ -1091,6 +1100,13 @@ impl AssocItem {
1091 AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"), 1100 AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"),
1092 } 1101 }
1093 } 1102 }
1103
1104 pub fn containing_trait(self, db: &dyn HirDatabase) -> Option<Trait> {
1105 match self.container(db) {
1106 AssocItemContainer::Trait(t) => Some(t),
1107 _ => None,
1108 }
1109 }
1094} 1110}
1095 1111
1096impl HasVisibility for AssocItem { 1112impl HasVisibility for AssocItem {