Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-def/src/nameres.rs13
-rw-r--r--crates/hir-def/src/nameres/collector.rs7
-rw-r--r--crates/hir-def/src/nameres/path_resolution.rs9
3 files changed, 12 insertions, 17 deletions
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index f44187ec59..b2c50f35be 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -842,9 +842,14 @@ impl MacroSubNs {
/// We ignore resolutions from one sub-namespace when searching names in scope for another.
///
/// [rustc]: https://github.com/rust-lang/rust/blob/1.69.0/compiler/rustc_resolve/src/macros.rs#L75
-fn sub_namespace_match(candidate: Option<MacroSubNs>, expected: Option<MacroSubNs>) -> bool {
- match (candidate, expected) {
- (Some(candidate), Some(expected)) => candidate == expected,
- _ => true,
+fn sub_namespace_match(
+ db: &dyn DefDatabase,
+ macro_id: MacroId,
+ expected: Option<MacroSubNs>,
+) -> bool {
+ let candidate = MacroSubNs::from_id(db, macro_id);
+ match expected {
+ Some(expected) => candidate == expected,
+ None => true,
}
}
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index a2ce538356..82c09156ea 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -2429,12 +2429,7 @@ impl ModCollector<'_, '_> {
})
.or_else(|| def_map[self.module_id].scope.get(name).take_macros())
.or_else(|| Some(def_map.macro_use_prelude.get(name).copied()?.0))
- .filter(|&id| {
- sub_namespace_match(
- Some(MacroSubNs::from_id(db, id)),
- Some(MacroSubNs::Bang),
- )
- })
+ .filter(|&id| sub_namespace_match(db, id, Some(MacroSubNs::Bang)))
.map(|it| self.def_collector.db.macro_def(it))
})
},
diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs
index 4641b220da..184a57410d 100644
--- a/crates/hir-def/src/nameres/path_resolution.rs
+++ b/crates/hir-def/src/nameres/path_resolution.rs
@@ -85,10 +85,7 @@ impl PerNs {
db: &dyn DefDatabase,
expected: Option<MacroSubNs>,
) -> Self {
- self.macros = self.macros.filter(|def| {
- let this = MacroSubNs::from_id(db, def.def);
- sub_namespace_match(Some(this), expected)
- });
+ self.macros = self.macros.filter(|def| sub_namespace_match(db, def.def, expected));
self
}
@@ -668,9 +665,7 @@ impl DefMap {
// FIXME: shadowing
.and_then(|it| it.last())
.copied()
- .filter(|&id| {
- sub_namespace_match(Some(MacroSubNs::from_id(db, id)), expected_macro_subns)
- })
+ .filter(|&id| sub_namespace_match(db, id, expected_macro_subns))
.map_or_else(PerNs::none, |m| PerNs::macros(m, Visibility::Public, None));
let from_scope = self[module].scope.get(name).filter_macro(db, expected_macro_subns);
let from_builtin = match self.block {