Skip to content

Commit 7ec8434

Browse files
committed
internal: remove potentially slow method
1 parent 3c5827c commit 7ec8434

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

crates/hir/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,6 @@ impl Module {
430430
.collect()
431431
}
432432

433-
/// XXX: this O(N) rather O(1) method, avoid using it if you can.
434-
pub fn visibility_of(self, db: &dyn HirDatabase, def: &ModuleDef) -> Option<Visibility> {
435-
let def_map = self.id.def_map(db.upcast());
436-
let module_data = &def_map[self.id.local_id];
437-
module_data.scope.visibility_of((*def).into())
438-
}
439-
440433
pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) {
441434
let _p = profile::span("Module::diagnostics").detail(|| {
442435
format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string()))

crates/hir_def/src/item_scope.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ impl ItemScope {
109109
self.values.values().copied()
110110
}
111111

112-
pub fn visibility_of(&self, def: ModuleDefId) -> Option<Visibility> {
113-
self.name_of(ItemInNs::Types(def))
114-
.or_else(|| self.name_of(ItemInNs::Values(def)))
115-
.map(|(_, v)| v)
116-
}
117-
118112
pub fn unnamed_consts(&self) -> impl Iterator<Item = ConstId> + '_ {
119113
self.unnamed_consts.iter().copied()
120114
}
@@ -138,6 +132,7 @@ impl ItemScope {
138132
}
139133
}
140134

135+
/// XXX: this is O(N) rather than O(1), try to not introduce new usages.
141136
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> {
142137
for (name, per_ns) in self.entries() {
143138
if let Some(vis) = item.match_with(per_ns) {

crates/ide/src/inlay_hints.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use either::Either;
2-
use hir::{known, Callable, HirDisplay, Semantics};
2+
use hir::{known, Callable, HasVisibility, HirDisplay, Semantics};
33
use ide_db::helpers::FamousDefs;
44
use ide_db::RootDatabase;
55
use stdx::to_lower_snake_case;
@@ -221,7 +221,11 @@ fn hint_iterator(
221221
let iter_mod = famous_defs.core_iter()?;
222222

223223
// Assert that this struct comes from `core::iter`.
224-
iter_mod.visibility_of(db, &strukt.into()).filter(|&vis| vis == hir::Visibility::Public)?;
224+
if !(strukt.visibility(db) == hir::Visibility::Public
225+
&& strukt.module(db).path_to_root(db).contains(&iter_mod))
226+
{
227+
return None;
228+
}
225229

226230
if ty.impls_trait(db, iter_trait, &[]) {
227231
let assoc_type_item = iter_trait.items(db).into_iter().find_map(|item| match item {

0 commit comments

Comments
 (0)