aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index be18c845c..e8e3211fc 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -148,6 +148,26 @@ impl ModuleDef {
148 ModuleDef::BuiltinType(_) => None, 148 ModuleDef::BuiltinType(_) => None,
149 } 149 }
150 } 150 }
151
152 pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> {
153 let module = match self {
154 ModuleDef::Module(it) => it.parent(db)?,
155 ModuleDef::Function(it) => return Some(it.visibility(db)),
156 ModuleDef::Adt(it) => it.module(db),
157 ModuleDef::EnumVariant(it) => {
158 let parent = it.parent_enum(db);
159 let module = it.module(db);
160 return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent)));
161 }
162 ModuleDef::Const(it) => return Some(it.visibility(db)),
163 ModuleDef::Static(it) => it.module(db),
164 ModuleDef::Trait(it) => it.module(db),
165 ModuleDef::TypeAlias(it) => return Some(it.visibility(db)),
166 ModuleDef::BuiltinType(_) => return None,
167 };
168
169 module.visibility_of(db, self)
170 }
151} 171}
152 172
153pub use hir_def::{ 173pub use hir_def::{
@@ -678,6 +698,10 @@ impl Static {
678 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { 698 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
679 db.static_data(self.id).name.clone() 699 db.static_data(self.id).name.clone()
680 } 700 }
701
702 pub fn is_mut(self, db: &dyn HirDatabase) -> bool {
703 db.static_data(self.id).mutable
704 }
681} 705}
682 706
683#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 707#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]