mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
internal: remove potentially slow method
This commit is contained in:
parent
3c5827cc18
commit
7ec8434674
@ -430,13 +430,6 @@ impl Module {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// XXX: this O(N) rather O(1) method, avoid using it if you can.
|
||||
pub fn visibility_of(self, db: &dyn HirDatabase, def: &ModuleDef) -> Option<Visibility> {
|
||||
let def_map = self.id.def_map(db.upcast());
|
||||
let module_data = &def_map[self.id.local_id];
|
||||
module_data.scope.visibility_of((*def).into())
|
||||
}
|
||||
|
||||
pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) {
|
||||
let _p = profile::span("Module::diagnostics").detail(|| {
|
||||
format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string()))
|
||||
|
@ -109,12 +109,6 @@ impl ItemScope {
|
||||
self.values.values().copied()
|
||||
}
|
||||
|
||||
pub fn visibility_of(&self, def: ModuleDefId) -> Option<Visibility> {
|
||||
self.name_of(ItemInNs::Types(def))
|
||||
.or_else(|| self.name_of(ItemInNs::Values(def)))
|
||||
.map(|(_, v)| v)
|
||||
}
|
||||
|
||||
pub fn unnamed_consts(&self) -> impl Iterator<Item = ConstId> + '_ {
|
||||
self.unnamed_consts.iter().copied()
|
||||
}
|
||||
@ -138,6 +132,7 @@ impl ItemScope {
|
||||
}
|
||||
}
|
||||
|
||||
/// XXX: this is O(N) rather than O(1), try to not introduce new usages.
|
||||
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> {
|
||||
for (name, per_ns) in self.entries() {
|
||||
if let Some(vis) = item.match_with(per_ns) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use either::Either;
|
||||
use hir::{known, Callable, HirDisplay, Semantics};
|
||||
use hir::{known, Callable, HasVisibility, HirDisplay, Semantics};
|
||||
use ide_db::helpers::FamousDefs;
|
||||
use ide_db::RootDatabase;
|
||||
use stdx::to_lower_snake_case;
|
||||
@ -221,7 +221,11 @@ fn hint_iterator(
|
||||
let iter_mod = famous_defs.core_iter()?;
|
||||
|
||||
// Assert that this struct comes from `core::iter`.
|
||||
iter_mod.visibility_of(db, &strukt.into()).filter(|&vis| vis == hir::Visibility::Public)?;
|
||||
if !(strukt.visibility(db) == hir::Visibility::Public
|
||||
&& strukt.module(db).path_to_root(db).contains(&iter_mod))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if ty.impls_trait(db, iter_trait, &[]) {
|
||||
let assoc_type_item = iter_trait.items(db).into_iter().find_map(|item| match item {
|
||||
|
Loading…
Reference in New Issue
Block a user