diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 106 |
1 files changed, 2 insertions, 104 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9b6276b51..c5539e076 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -30,7 +30,7 @@ use crate::{ | |||
30 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, | 30 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, |
31 | TypeAliasId, | 31 | TypeAliasId, |
32 | }, | 32 | }, |
33 | resolve::{Resolver, Scope, TypeNs}, | 33 | resolve::{HasResolver, TypeNs}, |
34 | ty::{InferenceResult, Namespace, TraitRef}, | 34 | ty::{InferenceResult, Namespace, TraitRef}, |
35 | Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, | 35 | Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, |
36 | }; | 36 | }; |
@@ -223,11 +223,6 @@ impl Module { | |||
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
227 | let def_map = db.crate_def_map(self.id.krate); | ||
228 | Resolver::default().push_module_scope(def_map, self.id.module_id) | ||
229 | } | ||
230 | |||
231 | pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { | 226 | pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { |
232 | let def_map = db.crate_def_map(self.id.krate); | 227 | let def_map = db.crate_def_map(self.id.krate); |
233 | def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect() | 228 | def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect() |
@@ -315,15 +310,6 @@ impl Struct { | |||
315 | db.type_for_def(self.into(), Namespace::Values) | 310 | db.type_for_def(self.into(), Namespace::Values) |
316 | } | 311 | } |
317 | 312 | ||
318 | // FIXME move to a more general type | ||
319 | /// Builds a resolver for type references inside this struct. | ||
320 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
321 | // take the outer scope... | ||
322 | let r = self.module(db).resolver(db); | ||
323 | // ...and add generic params, if present | ||
324 | r.push_generic_params_scope(db, self.into()) | ||
325 | } | ||
326 | |||
327 | fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { | 313 | fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { |
328 | db.struct_data(self.id.into()).variant_data.clone() | 314 | db.struct_data(self.id.into()).variant_data.clone() |
329 | } | 315 | } |
@@ -339,22 +325,13 @@ impl Union { | |||
339 | db.struct_data(self.id.into()).name.clone() | 325 | db.struct_data(self.id.into()).name.clone() |
340 | } | 326 | } |
341 | 327 | ||
342 | pub fn module(self, db: &impl HirDatabase) -> Module { | 328 | pub fn module(self, db: &impl DefDatabase) -> Module { |
343 | Module { id: self.id.0.module(db) } | 329 | Module { id: self.id.0.module(db) } |
344 | } | 330 | } |
345 | 331 | ||
346 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 332 | pub fn ty(self, db: &impl HirDatabase) -> Ty { |
347 | db.type_for_def(self.into(), Namespace::Types) | 333 | db.type_for_def(self.into(), Namespace::Types) |
348 | } | 334 | } |
349 | |||
350 | // FIXME move to a more general type | ||
351 | /// Builds a resolver for type references inside this union. | ||
352 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
353 | // take the outer scope... | ||
354 | let r = self.module(db).resolver(db); | ||
355 | // ...and add generic params, if present | ||
356 | r.push_generic_params_scope(db, self.into()) | ||
357 | } | ||
358 | } | 335 | } |
359 | 336 | ||
360 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 337 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -394,16 +371,6 @@ impl Enum { | |||
394 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 371 | pub fn ty(self, db: &impl HirDatabase) -> Ty { |
395 | db.type_for_def(self.into(), Namespace::Types) | 372 | db.type_for_def(self.into(), Namespace::Types) |
396 | } | 373 | } |
397 | |||
398 | // FIXME: move to a more general type | ||
399 | /// Builds a resolver for type references inside this struct. | ||
400 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
401 | // take the outer scope... | ||
402 | let r = self.module(db).resolver(db); | ||
403 | // ...and add generic params, if present | ||
404 | let r = r.push_generic_params_scope(db, self.into()); | ||
405 | r.push_scope(Scope::AdtScope(self.into())) | ||
406 | } | ||
407 | } | 374 | } |
408 | 375 | ||
409 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 376 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -475,14 +442,6 @@ impl Adt { | |||
475 | .krate(), | 442 | .krate(), |
476 | ) | 443 | ) |
477 | } | 444 | } |
478 | |||
479 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
480 | match self { | ||
481 | Adt::Struct(it) => it.resolver(db), | ||
482 | Adt::Union(it) => it.resolver(db), | ||
483 | Adt::Enum(it) => it.resolver(db), | ||
484 | } | ||
485 | } | ||
486 | } | 445 | } |
487 | 446 | ||
488 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 447 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -533,15 +492,6 @@ pub enum DefWithBody { | |||
533 | impl_froms!(DefWithBody: Function, Const, Static); | 492 | impl_froms!(DefWithBody: Function, Const, Static); |
534 | 493 | ||
535 | impl DefWithBody { | 494 | impl DefWithBody { |
536 | /// Builds a resolver for code inside this item. | ||
537 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
538 | match self { | ||
539 | DefWithBody::Const(c) => c.resolver(db), | ||
540 | DefWithBody::Function(f) => f.resolver(db), | ||
541 | DefWithBody::Static(s) => s.resolver(db), | ||
542 | } | ||
543 | } | ||
544 | |||
545 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | 495 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { |
546 | match self { | 496 | match self { |
547 | DefWithBody::Const(c) => c.krate(db), | 497 | DefWithBody::Const(c) => c.krate(db), |
@@ -738,15 +688,6 @@ impl Function { | |||
738 | } | 688 | } |
739 | } | 689 | } |
740 | 690 | ||
741 | // FIXME: move to a more general type for 'body-having' items | ||
742 | /// Builds a resolver for code inside this item. | ||
743 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
744 | // take the outer scope... | ||
745 | let r = self.container(db).map_or_else(|| self.module(db).resolver(db), |c| c.resolver(db)); | ||
746 | // ...and add generic params, if present | ||
747 | r.push_generic_params_scope(db, self.into()) | ||
748 | } | ||
749 | |||
750 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { | 691 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { |
751 | let infer = self.infer(db); | 692 | let infer = self.infer(db); |
752 | infer.add_diagnostics(db, self, sink); | 693 | infer.add_diagnostics(db, self, sink); |
@@ -804,17 +745,6 @@ impl Const { | |||
804 | ContainerId::ModuleId(_) => None, | 745 | ContainerId::ModuleId(_) => None, |
805 | } | 746 | } |
806 | } | 747 | } |
807 | |||
808 | // FIXME: move to a more general type for 'body-having' items | ||
809 | /// Builds a resolver for code inside this item. | ||
810 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
811 | // take the outer scope... | ||
812 | let r = self | ||
813 | .impl_block(db) | ||
814 | .map(|ib| ib.resolver(db)) | ||
815 | .unwrap_or_else(|| self.module(db).resolver(db)); | ||
816 | r | ||
817 | } | ||
818 | } | 748 | } |
819 | 749 | ||
820 | #[derive(Debug, Clone, PartialEq, Eq)] | 750 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -874,12 +804,6 @@ impl Static { | |||
874 | db.static_data(self) | 804 | db.static_data(self) |
875 | } | 805 | } |
876 | 806 | ||
877 | /// Builds a resolver for code inside this item. | ||
878 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
879 | // take the outer scope... | ||
880 | self.module(db).resolver(db) | ||
881 | } | ||
882 | |||
883 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 807 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
884 | db.infer(self.into()) | 808 | db.infer(self.into()) |
885 | } | 809 | } |
@@ -975,12 +899,6 @@ impl Trait { | |||
975 | pub fn is_auto(self, db: &impl DefDatabase) -> bool { | 899 | pub fn is_auto(self, db: &impl DefDatabase) -> bool { |
976 | self.trait_data(db).auto | 900 | self.trait_data(db).auto |
977 | } | 901 | } |
978 | |||
979 | pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
980 | let r = self.module(db).resolver(db); | ||
981 | // add generic params, if present | ||
982 | r.push_generic_params_scope(db, self.into()) | ||
983 | } | ||
984 | } | 902 | } |
985 | 903 | ||
986 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 904 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -1032,17 +950,6 @@ impl TypeAlias { | |||
1032 | pub fn name(self, db: &impl DefDatabase) -> Name { | 950 | pub fn name(self, db: &impl DefDatabase) -> Name { |
1033 | db.type_alias_data(self).name.clone() | 951 | db.type_alias_data(self).name.clone() |
1034 | } | 952 | } |
1035 | |||
1036 | /// Builds a resolver for the type references in this type alias. | ||
1037 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
1038 | // take the outer scope... | ||
1039 | let r = self | ||
1040 | .impl_block(db) | ||
1041 | .map(|ib| ib.resolver(db)) | ||
1042 | .unwrap_or_else(|| self.module(db).resolver(db)); | ||
1043 | // ...and add generic params, if present | ||
1044 | r.push_generic_params_scope(db, self.into()) | ||
1045 | } | ||
1046 | } | 953 | } |
1047 | 954 | ||
1048 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 955 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -1058,15 +965,6 @@ pub enum Container { | |||
1058 | } | 965 | } |
1059 | impl_froms!(Container: Trait, ImplBlock); | 966 | impl_froms!(Container: Trait, ImplBlock); |
1060 | 967 | ||
1061 | impl Container { | ||
1062 | pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
1063 | match self { | ||
1064 | Container::Trait(trait_) => trait_.resolver(db), | ||
1065 | Container::ImplBlock(impl_block) => impl_block.resolver(db), | ||
1066 | } | ||
1067 | } | ||
1068 | } | ||
1069 | |||
1070 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | 968 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
1071 | pub enum AssocItem { | 969 | pub enum AssocItem { |
1072 | Function(Function), | 970 | Function(Function), |