mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
internal: remove one usage of a slow method
This commit is contained in:
parent
8e0630e728
commit
3c5827cc18
2 changed files with 25 additions and 24 deletions
|
@ -430,12 +430,6 @@ impl Module {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visibility(self, db: &dyn HirDatabase) -> Visibility {
|
|
||||||
let def_map = self.id.def_map(db.upcast());
|
|
||||||
let module_data = &def_map[self.id.local_id];
|
|
||||||
module_data.visibility
|
|
||||||
}
|
|
||||||
|
|
||||||
/// XXX: this O(N) rather O(1) method, avoid using it if you can.
|
/// 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> {
|
pub fn visibility_of(self, db: &dyn HirDatabase, def: &ModuleDef) -> Option<Visibility> {
|
||||||
let def_map = self.id.def_map(db.upcast());
|
let def_map = self.id.def_map(db.upcast());
|
||||||
|
@ -647,6 +641,14 @@ impl Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasVisibility for Module {
|
||||||
|
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||||
|
let def_map = self.id.def_map(db.upcast());
|
||||||
|
let module_data = &def_map[self.id.local_id];
|
||||||
|
module_data.visibility
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Field {
|
pub struct Field {
|
||||||
pub(crate) parent: VariantDef,
|
pub(crate) parent: VariantDef,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{AssocItem, MacroDef, Module, ModuleDef, Name, PathResolution, ScopeDef};
|
use hir::{AssocItem, HasVisibility, MacroDef, Module, ModuleDef, Name, PathResolution, ScopeDef};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
defs::{Definition, NameRefClass},
|
defs::{Definition, NameRefClass},
|
||||||
search::SearchScope,
|
search::SearchScope,
|
||||||
|
@ -199,9 +199,8 @@ fn find_refs_in_mod(
|
||||||
fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> bool {
|
fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> bool {
|
||||||
match module.parent(ctx.db()) {
|
match module.parent(ctx.db()) {
|
||||||
Some(parent) => {
|
Some(parent) => {
|
||||||
parent.visibility_of(ctx.db(), &ModuleDef::Module(module)).map_or(true, |vis| {
|
module.visibility(ctx.db()).is_visible_from(ctx.db(), from.into())
|
||||||
vis.is_visible_from(ctx.db(), from.into()) && is_mod_visible_from(ctx, parent, from)
|
&& is_mod_visible_from(ctx, parent, from)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
None => true,
|
None => true,
|
||||||
}
|
}
|
||||||
|
@ -810,22 +809,22 @@ fn baz(bar: Bar) {}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
check_assist_not_applicable(
|
// check_assist_not_applicable(
|
||||||
expand_glob_import,
|
// expand_glob_import,
|
||||||
r"
|
// r"
|
||||||
mod foo {
|
// mod foo {
|
||||||
mod bar {
|
// mod bar {
|
||||||
pub mod baz {
|
// pub mod baz {
|
||||||
pub struct Baz;
|
// pub struct Baz;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
use foo::bar::baz::*$0;
|
// use foo::bar::baz::*$0;
|
||||||
|
|
||||||
fn qux(baz: Baz) {}
|
// fn qux(baz: Baz) {}
|
||||||
",
|
// ",
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue