diff --git a/crates/hir-def/src/child_by_source.rs b/crates/hir-def/src/child_by_source.rs index 5b1435e8f44..bb13165257b 100644 --- a/crates/hir-def/src/child_by_source.rs +++ b/crates/hir-def/src/child_by_source.rs @@ -198,6 +198,10 @@ fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, _: HirFileI impl ChildBySource for DefWithBodyId { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) { let body = db.body(*self); + if let &DefWithBodyId::VariantId(v) = self { + VariantId::EnumVariantId(v).child_by_source_to(db, res, file_id) + } + for (_, def_map) in body.blocks(db) { // All block expressions are merged into the same map, because they logically all add // inner items to the containing `DefWithBodyId`. diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 1c48d2ff081..9fcaac85bce 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -377,10 +377,10 @@ pub fn as_def_with_body(self) -> Option { ModuleDef::Function(it) => Some(it.into()), ModuleDef::Const(it) => Some(it.into()), ModuleDef::Static(it) => Some(it.into()), + ModuleDef::Variant(it) => Some(it.into()), ModuleDef::Module(_) | ModuleDef::Adt(_) - | ModuleDef::Variant(_) | ModuleDef::Trait(_) | ModuleDef::TypeAlias(_) | ModuleDef::Macro(_) @@ -1160,7 +1160,7 @@ pub enum DefWithBody { Const(Const), Variant(Variant), } -impl_from!(Function, Const, Static for DefWithBody); +impl_from!(Function, Const, Static, Variant for DefWithBody); impl DefWithBody { pub fn module(self, db: &dyn HirDatabase) -> Module { diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 87e22c2138b..fa45e3c12eb 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -384,7 +384,7 @@ fn container_to_def(&mut self, container: InFile) -> Option