mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Make resolve_name_in_module a bit more lazy
This commit is contained in:
parent
25090f0e6d
commit
88b19cc39b
@ -397,14 +397,15 @@ impl DefMap {
|
||||
Some(_) | None => from_scope.or(from_builtin),
|
||||
},
|
||||
};
|
||||
let from_extern_prelude = self
|
||||
.extern_prelude
|
||||
.get(name)
|
||||
.map_or(PerNs::none(), |&it| PerNs::types(it.into(), Visibility::Public));
|
||||
|
||||
let from_prelude = self.resolve_in_prelude(db, name);
|
||||
let extern_prelude = || {
|
||||
self.extern_prelude
|
||||
.get(name)
|
||||
.map_or(PerNs::none(), |&it| PerNs::types(it.into(), Visibility::Public))
|
||||
};
|
||||
let prelude = || self.resolve_in_prelude(db, name);
|
||||
|
||||
from_legacy_macro.or(from_scope_or_builtin).or(from_extern_prelude).or(from_prelude)
|
||||
from_legacy_macro.or(from_scope_or_builtin).or_else(extern_prelude).or_else(prelude)
|
||||
}
|
||||
|
||||
fn resolve_name_in_crate_root_or_extern_prelude(
|
||||
@ -412,20 +413,19 @@ impl DefMap {
|
||||
db: &dyn DefDatabase,
|
||||
name: &Name,
|
||||
) -> PerNs {
|
||||
let arc;
|
||||
let crate_def_map = match self.block {
|
||||
let from_crate_root = match self.block {
|
||||
Some(_) => {
|
||||
arc = self.crate_root(db).def_map(db);
|
||||
&arc
|
||||
let def_map = self.crate_root(db).def_map(db);
|
||||
def_map[def_map.root].scope.get(name)
|
||||
}
|
||||
None => self,
|
||||
None => self[self.root].scope.get(name),
|
||||
};
|
||||
let from_extern_prelude = || {
|
||||
self.resolve_name_in_extern_prelude(db, name)
|
||||
.map_or(PerNs::none(), |it| PerNs::types(it.into(), Visibility::Public))
|
||||
};
|
||||
let from_crate_root = crate_def_map[crate_def_map.root].scope.get(name);
|
||||
let from_extern_prelude = self
|
||||
.resolve_name_in_extern_prelude(db, name)
|
||||
.map_or(PerNs::none(), |it| PerNs::types(it.into(), Visibility::Public));
|
||||
|
||||
from_crate_root.or(from_extern_prelude)
|
||||
from_crate_root.or_else(from_extern_prelude)
|
||||
}
|
||||
|
||||
fn resolve_in_prelude(&self, db: &dyn DefDatabase, name: &Name) -> PerNs {
|
||||
|
@ -43,6 +43,10 @@ impl PerNs {
|
||||
self.types.is_none() && self.values.is_none() && self.macros.is_none()
|
||||
}
|
||||
|
||||
pub fn is_full(&self) -> bool {
|
||||
self.types.is_some() && self.values.is_some() && self.macros.is_some()
|
||||
}
|
||||
|
||||
pub fn take_types(self) -> Option<ModuleDefId> {
|
||||
self.types.map(|it| it.0)
|
||||
}
|
||||
@ -84,6 +88,14 @@ impl PerNs {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn or_else(self, f: impl FnOnce() -> PerNs) -> PerNs {
|
||||
if self.is_full() {
|
||||
self
|
||||
} else {
|
||||
self.or(f())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter_items(self) -> impl Iterator<Item = ItemInNs> {
|
||||
let _p = profile::span("PerNs::iter_items");
|
||||
self.types
|
||||
|
Loading…
Reference in New Issue
Block a user