]> git.lizzy.rs Git - rust.git/commitdiff
Fix legacy macro resolution in block expressions
authorJonas Schievink <jonasschievink@gmail.com>
Wed, 27 Jan 2021 18:16:29 +0000 (19:16 +0100)
committerJonas Schievink <jonasschievink@gmail.com>
Wed, 27 Jan 2021 18:16:39 +0000 (19:16 +0100)
crates/hir_def/src/nameres.rs
crates/hir_def/src/nameres/collector.rs

index 199771e9a83b568870ddb705503b54103c2f8886..005b36e02887ef244ba9808bac5b2eac08e3775d 100644 (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 {
index 393170b32f1ecf491d6e9af88cd0b784685298f0..761b29c868c06728014821ec2be1640400992d82 100644 (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))
                 })
             })
         {