aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-05-18 16:51:02 +0100
committerJonas Schievink <[email protected]>2021-05-18 16:51:02 +0100
commit4884d9ec1deec8d4bbbe240dab1107c7cb8dd688 (patch)
tree7792c7c910ee109a441b25f15b425c78ac66a67d /crates
parent312f1fe20a6a0a8e69834c66f51b9abc9db5e0ce (diff)
Simplify `DefCollector::resolve_macros`
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/nameres/collector.rs36
1 files changed, 13 insertions, 23 deletions
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<'_> {
806 let mut resolved = Vec::new(); 806 let mut resolved = Vec::new();
807 let mut res = ReachedFixedPoint::Yes; 807 let mut res = ReachedFixedPoint::Yes;
808 macros.retain(|directive| { 808 macros.retain(|directive| {
809 let resolver = |path| {
810 let resolved_res = self.def_map.resolve_path_fp_with_macro(
811 self.db,
812 ResolveMode::Other,
813 directive.module_id,
814 &path,
815 BuiltinShadowMode::Module,
816 );
817 resolved_res.resolved_def.take_macros()
818 };
819
809 match &directive.kind { 820 match &directive.kind {
810 MacroDirectiveKind::FnLike { ast_id, fragment } => { 821 MacroDirectiveKind::FnLike { ast_id, fragment } => {
811 match macro_call_as_call_id( 822 match macro_call_as_call_id(
@@ -813,16 +824,7 @@ impl DefCollector<'_> {
813 *fragment, 824 *fragment,
814 self.db, 825 self.db,
815 self.def_map.krate, 826 self.def_map.krate,
816 |path| { 827 &resolver,
817 let resolved_res = self.def_map.resolve_path_fp_with_macro(
818 self.db,
819 ResolveMode::Other,
820 directive.module_id,
821 &path,
822 BuiltinShadowMode::Module,
823 );
824 resolved_res.resolved_def.take_macros()
825 },
826 &mut |_err| (), 828 &mut |_err| (),
827 ) { 829 ) {
828 Ok(Ok(call_id)) => { 830 Ok(Ok(call_id)) => {
@@ -839,7 +841,7 @@ impl DefCollector<'_> {
839 *derive_attr, 841 *derive_attr,
840 self.db, 842 self.db,
841 self.def_map.krate, 843 self.def_map.krate,
842 |path| self.resolve_derive_macro(directive.module_id, &path), 844 &resolver,
843 ) { 845 ) {
844 Ok(call_id) => { 846 Ok(call_id) => {
845 resolved.push((directive.module_id, call_id, directive.depth)); 847 resolved.push((directive.module_id, call_id, directive.depth));
@@ -862,18 +864,6 @@ impl DefCollector<'_> {
862 res 864 res
863 } 865 }
864 866
865 fn resolve_derive_macro(&self, module: LocalModuleId, path: &ModPath) -> Option<MacroDefId> {
866 let resolved_res = self.def_map.resolve_path_fp_with_macro(
867 self.db,
868 ResolveMode::Other,
869 module,
870 &path,
871 BuiltinShadowMode::Module,
872 );
873
874 resolved_res.resolved_def.take_macros()
875 }
876
877 fn collect_macro_expansion( 867 fn collect_macro_expansion(
878 &mut self, 868 &mut self,
879 module_id: LocalModuleId, 869 module_id: LocalModuleId,