diff options
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 031c91ccf..650b4fa40 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -186,6 +186,16 @@ impl_from!( | |||
186 | for ModuleDef | 186 | for ModuleDef |
187 | ); | 187 | ); |
188 | 188 | ||
189 | impl From<VariantDef> for ModuleDef { | ||
190 | fn from(var: VariantDef) -> Self { | ||
191 | match var { | ||
192 | VariantDef::Struct(t) => Adt::from(t).into(), | ||
193 | VariantDef::Union(t) => Adt::from(t).into(), | ||
194 | VariantDef::EnumVariant(t) => t.into(), | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
189 | impl ModuleDef { | 199 | impl ModuleDef { |
190 | pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { | 200 | pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { |
191 | match self { | 201 | match self { |
@@ -752,6 +762,13 @@ impl Function { | |||
752 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | 762 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { |
753 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) | 763 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) |
754 | } | 764 | } |
765 | |||
766 | /// Whether this function declaration has a definition. | ||
767 | /// | ||
768 | /// This is false in the case of required (not provided) trait methods. | ||
769 | pub fn has_body(self, db: &dyn HirDatabase) -> bool { | ||
770 | db.function_data(self.id).has_body | ||
771 | } | ||
755 | } | 772 | } |
756 | 773 | ||
757 | // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. | 774 | // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. |