From 4884d9ec1deec8d4bbbe240dab1107c7cb8dd688 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 18 May 2021 17:51:02 +0200 Subject: Simplify `DefCollector::resolve_macros` --- crates/hir_def/src/nameres/collector.rs | 36 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index adfb78c94..a68674c10 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -806,6 +806,17 @@ impl DefCollector<'_> { let mut resolved = Vec::new(); let mut res = ReachedFixedPoint::Yes; macros.retain(|directive| { + let resolver = |path| { + let resolved_res = self.def_map.resolve_path_fp_with_macro( + self.db, + ResolveMode::Other, + directive.module_id, + &path, + BuiltinShadowMode::Module, + ); + resolved_res.resolved_def.take_macros() + }; + match &directive.kind { MacroDirectiveKind::FnLike { ast_id, fragment } => { match macro_call_as_call_id( @@ -813,16 +824,7 @@ impl DefCollector<'_> { *fragment, self.db, self.def_map.krate, - |path| { - let resolved_res = self.def_map.resolve_path_fp_with_macro( - self.db, - ResolveMode::Other, - directive.module_id, - &path, - BuiltinShadowMode::Module, - ); - resolved_res.resolved_def.take_macros() - }, + &resolver, &mut |_err| (), ) { Ok(Ok(call_id)) => { @@ -839,7 +841,7 @@ impl DefCollector<'_> { *derive_attr, self.db, self.def_map.krate, - |path| self.resolve_derive_macro(directive.module_id, &path), + &resolver, ) { Ok(call_id) => { resolved.push((directive.module_id, call_id, directive.depth)); @@ -862,18 +864,6 @@ impl DefCollector<'_> { res } - fn resolve_derive_macro(&self, module: LocalModuleId, path: &ModPath) -> Option { - let resolved_res = self.def_map.resolve_path_fp_with_macro( - self.db, - ResolveMode::Other, - module, - &path, - BuiltinShadowMode::Module, - ); - - resolved_res.resolved_def.take_macros() - } - fn collect_macro_expansion( &mut self, module_id: LocalModuleId, -- cgit v1.2.3