diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-27 18:17:54 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-27 18:17:54 +0000 |
commit | 671757a5de0bbbdd8f42cd3c2d859a75288e3880 (patch) | |
tree | 0008faa828f5eea1ff03c0436c13c5afbd40a73c /crates/hir_def/src | |
parent | 0ebf548ab7e00676d8ca43d6617c30c1ea840fc7 (diff) | |
parent | ad254f4c972b7a211fe2ebae4ecea47a79d02d9b (diff) |
Merge #7466
7466: Fix legacy macro resolution in block expressions r=jonas-schievink a=jonas-schievink
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/nameres.rs | 11 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 199771e9a..005b36e02 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -289,6 +289,17 @@ impl DefMap { | |||
289 | (res.resolved_def, res.segment_index) | 289 | (res.resolved_def, res.segment_index) |
290 | } | 290 | } |
291 | 291 | ||
292 | /// Iterates over the containing `DefMap`s, if `self` is a `DefMap` corresponding to a block | ||
293 | /// expression. | ||
294 | fn ancestor_maps( | ||
295 | &self, | ||
296 | local_mod: LocalModuleId, | ||
297 | ) -> impl Iterator<Item = (&DefMap, LocalModuleId)> { | ||
298 | std::iter::successors(Some((self, local_mod)), |(map, _)| { | ||
299 | map.block.as_ref().map(|block| (&*block.parent, block.parent_module)) | ||
300 | }) | ||
301 | } | ||
302 | |||
292 | // FIXME: this can use some more human-readable format (ideally, an IR | 303 | // FIXME: this can use some more human-readable format (ideally, an IR |
293 | // even), as this should be a great debugging aid. | 304 | // even), as this should be a great debugging aid. |
294 | pub fn dump(&self) -> String { | 305 | pub fn dump(&self) -> String { |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 393170b32..761b29c86 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1443,7 +1443,10 @@ impl ModCollector<'_, '_> { | |||
1443 | if let Some(macro_call_id) = | 1443 | if let Some(macro_call_id) = |
1444 | ast_id.as_call_id(self.def_collector.db, self.def_collector.def_map.krate, |path| { | 1444 | ast_id.as_call_id(self.def_collector.db, self.def_collector.def_map.krate, |path| { |
1445 | path.as_ident().and_then(|name| { | 1445 | path.as_ident().and_then(|name| { |
1446 | self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) | 1446 | self.def_collector |
1447 | .def_map | ||
1448 | .ancestor_maps(self.module_id) | ||
1449 | .find_map(|(map, module)| map[module].scope.get_legacy_macro(&name)) | ||
1447 | }) | 1450 | }) |
1448 | }) | 1451 | }) |
1449 | { | 1452 | { |