diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index be18c845c..840cfdfc8 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 | ||
153 | pub use hir_def::{ | 173 | pub 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)] |
@@ -965,6 +989,17 @@ impl TypeParam { | |||
965 | ty: InEnvironment { value: ty, environment }, | 989 | ty: InEnvironment { value: ty, environment }, |
966 | } | 990 | } |
967 | } | 991 | } |
992 | |||
993 | pub fn default(self, db: &dyn HirDatabase) -> Option<Type> { | ||
994 | let params = db.generic_defaults(self.id.parent); | ||
995 | let local_idx = hir_ty::param_idx(db, self.id)?; | ||
996 | let resolver = self.id.parent.resolver(db.upcast()); | ||
997 | let environment = TraitEnvironment::lower(db, &resolver); | ||
998 | params.get(local_idx).cloned().map(|ty| Type { | ||
999 | krate: self.id.parent.module(db.upcast()).krate, | ||
1000 | ty: InEnvironment { value: ty, environment }, | ||
1001 | }) | ||
1002 | } | ||
968 | } | 1003 | } |
969 | 1004 | ||
970 | // FIXME: rename from `ImplDef` to `Impl` | 1005 | // FIXME: rename from `ImplDef` to `Impl` |