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,14 +811,7 @@ impl DefCollector<'_> {
let mut resolved = Vec::new();
let mut res = ReachedFixedPoint::Yes;
macros.retain(|directive| {
match &directive.kind {
MacroDirectiveKind::FnLike { ast_id, fragment } => {
match macro_call_as_call_id(
ast_id,
*fragment,
self.db,
self.def_map.krate,
|path| {
let resolver = |path| {
let resolved_res = self.def_map.resolve_path_fp_with_macro(
self.db,
ResolveMode::Other,
@ -827,7 +820,16 @@ impl DefCollector<'_> {
BuiltinShadowMode::Module,
);
resolved_res.resolved_def.take_macros()
},
};
match &directive.kind {
MacroDirectiveKind::FnLike { ast_id, fragment } => {
match macro_call_as_call_id(
ast_id,
*fragment,
self.db,
self.def_map.krate,
&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,