From 0231d19f3fba410896d52fa345fe1967c2ea8f55 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 24 Sep 2022 03:07:05 +0200 Subject: [PATCH] Fix diagnostics not working in enum variant bodies --- crates/hir/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 9fcaac85bce..e1f69001e80 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -50,7 +50,7 @@ resolver::{HasResolver, Resolver}, src::HasSource as _, AdtId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, - FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId, + EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId, LocalEnumVariantId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId, }; @@ -348,7 +348,10 @@ pub fn diagnostics(self, db: &dyn HirDatabase) -> Vec { ModuleDef::Module(it) => it.id.into(), ModuleDef::Const(it) => it.id.into(), ModuleDef::Static(it) => it.id.into(), - _ => return Vec::new(), + ModuleDef::Variant(it) => { + EnumVariantId { parent: it.parent.into(), local_id: it.id }.into() + } + ModuleDef::BuiltinType(_) | ModuleDef::Macro(_) => return Vec::new(), }; let module = match self.module(db) { @@ -537,6 +540,12 @@ pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec) { } acc.extend(decl.diagnostics(db)) } + ModuleDef::Adt(Adt::Enum(e)) => { + for v in e.variants(db) { + acc.extend(ModuleDef::Variant(v).diagnostics(db)); + } + acc.extend(decl.diagnostics(db)) + } _ => acc.extend(decl.diagnostics(db)), } }