Simplify DefCollector::resolve_macros

This commit is contained in:
Jonas Schievink 2021-05-18 17:51:02 +02:00
parent 312f1fe20a
commit 4884d9ec1d

View File

@ -806,6 +806,17 @@ fn resolve_macros(&mut self) -> ReachedFixedPoint {
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 @@ fn resolve_macros(&mut self) -> ReachedFixedPoint {
*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 @@ fn resolve_macros(&mut self) -> ReachedFixedPoint {
*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 @@ fn resolve_macros(&mut self) -> ReachedFixedPoint {
res
}
fn resolve_derive_macro(&self, module: LocalModuleId, path: &ModPath) -> Option<MacroDefId> {
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,