From 93aeb16eb21709de38ba8484fa82ed4e05ae5665 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 19 Mar 2021 19:56:13 +0100 Subject: Return `Either` from `MacroDefId::ast_id` --- crates/hir/src/has_source.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index d57fad9ed..dc10a4d0f 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -6,7 +6,7 @@ use hir_def::{ src::{HasChildSource, HasSource as _}, Lookup, VariantId, }; -use hir_expand::{InFile, MacroDefKind}; +use hir_expand::InFile; use syntax::ast; use crate::{ @@ -113,15 +113,10 @@ impl HasSource for TypeAlias { impl HasSource for MacroDef { type Ast = Either; fn source(self, db: &dyn HirDatabase) -> Option> { - Some(match &self.id.kind { - MacroDefKind::Declarative(id) - | MacroDefKind::BuiltIn(_, id) - | MacroDefKind::BuiltInDerive(_, id) - | MacroDefKind::BuiltInEager(_, id) => { - id.with_value(Either::Left(id.to_node(db.upcast()))) - } - MacroDefKind::ProcMacro(_, id) => id.map(|_| Either::Right(id.to_node(db.upcast()))), - }) + Some(self.id.ast_id().either( + |id| id.with_value(Either::Left(id.to_node(db.upcast()))), + |id| id.with_value(Either::Right(id.to_node(db.upcast()))), + )) } } impl HasSource for Impl { -- cgit v1.2.3