8871: internal: Simplify `DefCollector::resolve_macros` r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-05-18 19:02:32 +00:00 committed by GitHub
commit 16b03d21dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -811,6 +811,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(
@ -818,16 +829,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)) => {
@ -844,7 +846,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));
@ -867,18 +869,6 @@ impl DefCollector<'_> {
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,