Inline macro sub-namespace lookup into sub_namespace_match

This commit is contained in:
Zalathar 2025-11-23 17:52:07 +11:00
parent cf4b1faea3
commit ac46f2334f
3 changed files with 12 additions and 17 deletions

View file

@ -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,
}
}

View file

@ -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))
})
},

View file

@ -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 {