7466: Fix legacy macro resolution in block expressions r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-01-27 18:17:54 +00:00 committed by GitHub
commit 671757a5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -289,6 +289,17 @@ pub(crate) fn resolve_path(
(res.resolved_def, res.segment_index)
}
/// Iterates over the containing `DefMap`s, if `self` is a `DefMap` corresponding to a block
/// expression.
fn ancestor_maps(
&self,
local_mod: LocalModuleId,
) -> impl Iterator<Item = (&DefMap, LocalModuleId)> {
std::iter::successors(Some((self, local_mod)), |(map, _)| {
map.block.as_ref().map(|block| (&*block.parent, block.parent_module))
})
}
// FIXME: this can use some more human-readable format (ideally, an IR
// even), as this should be a great debugging aid.
pub fn dump(&self) -> String {

View File

@ -1443,7 +1443,10 @@ fn collect_macro_call(&mut self, mac: &MacroCall) {
if let Some(macro_call_id) =
ast_id.as_call_id(self.def_collector.db, self.def_collector.def_map.krate, |path| {
path.as_ident().and_then(|name| {
self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name)
self.def_collector
.def_map
.ancestor_maps(self.module_id)
.find_map(|(map, module)| map[module].scope.get_legacy_macro(&name))
})
})
{