mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
internal: remove one more accidentally quadratic code-path
Definition::visibility was implemented in a rather roundabout way -- by asking the parent module about the effective visibility. This is problematic for a couple of reasons: * first, it doesn't work for local items * second, asking module about visibility of a child is a linear operation (that's a problem in itself, tracked in #9378) Instead, lets ask the declared visibility directly, we have all the code for it, and need only to actually us it.
This commit is contained in:
parent
9239943b84
commit
7be2d2f008
2 changed files with 32 additions and 26 deletions
|
@ -303,26 +303,6 @@ impl ModuleDef {
|
|||
Some(segments.join("::"))
|
||||
}
|
||||
|
||||
pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> {
|
||||
let module = match self {
|
||||
ModuleDef::Module(it) => it.parent(db)?,
|
||||
ModuleDef::Function(it) => return Some(it.visibility(db)),
|
||||
ModuleDef::Adt(it) => it.module(db),
|
||||
ModuleDef::Variant(it) => {
|
||||
let parent = it.parent_enum(db);
|
||||
let module = it.module(db);
|
||||
return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent)));
|
||||
}
|
||||
ModuleDef::Const(it) => return Some(it.visibility(db)),
|
||||
ModuleDef::Static(it) => it.module(db),
|
||||
ModuleDef::Trait(it) => it.module(db),
|
||||
ModuleDef::TypeAlias(it) => return Some(it.visibility(db)),
|
||||
ModuleDef::BuiltinType(_) => return None,
|
||||
};
|
||||
|
||||
module.visibility_of(db, self)
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
match self {
|
||||
ModuleDef::Adt(it) => Some(it.name(db)),
|
||||
|
@ -893,6 +873,16 @@ impl Adt {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Adt {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
match self {
|
||||
Adt::Struct(it) => it.visibility(db),
|
||||
Adt::Union(it) => it.visibility(db),
|
||||
Adt::Enum(it) => it.visibility(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum VariantDef {
|
||||
Struct(Struct),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue