mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-23 08:48:08 +00:00
Inline macro sub-namespace lookup into sub_namespace_match
This commit is contained in:
parent
cf4b1faea3
commit
ac46f2334f
3 changed files with 12 additions and 17 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
})
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue