diff options
author | Aleksey Kladov <[email protected]> | 2019-11-20 18:55:33 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-20 19:22:32 +0000 |
commit | 6241cf9a598b19cbd6c8c41c3743f8d56adafd2b (patch) | |
tree | 632e060e2db216d2e9bed0414a37578a35ee4a61 /crates/ra_hir/src | |
parent | 7c275a7ed2253fc7bd8b46c685a754c4d4e9dee3 (diff) |
Add HasResolver trait
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 106 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 131 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 2 |
8 files changed, 138 insertions, 134 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), |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 8bfdda45e..869879bdf 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -11,6 +11,7 @@ use rustc_hash::FxHashSet; | |||
11 | use crate::{ | 11 | use crate::{ |
12 | db::HirDatabase, | 12 | db::HirDatabase, |
13 | diagnostics::{MissingFields, MissingOkInTailExpr}, | 13 | diagnostics::{MissingFields, MissingOkInTailExpr}, |
14 | resolve::HasResolver, | ||
14 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, | 15 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, |
15 | Adt, DefWithBody, Function, HasBody, Name, Path, Resolver, | 16 | Adt, DefWithBody, Function, HasBody, Name, Path, Resolver, |
16 | }; | 17 | }; |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 54ed03642..f1bf2ee9d 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -2,8 +2,8 @@ | |||
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | db::{DefDatabase, HirDatabase}, | 5 | db::DefDatabase, Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, |
6 | Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, TypeAlias, Union, | 6 | TypeAlias, Union, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | pub use hir_def::generics::{GenericParam, GenericParams, WherePredicate}; | 9 | pub use hir_def::generics::{GenericParam, GenericParams, WherePredicate}; |
@@ -31,20 +31,6 @@ impl_froms!( | |||
31 | Const | 31 | Const |
32 | ); | 32 | ); |
33 | 33 | ||
34 | impl GenericDef { | ||
35 | pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { | ||
36 | match self { | ||
37 | GenericDef::Function(inner) => inner.resolver(db), | ||
38 | GenericDef::Adt(adt) => adt.resolver(db), | ||
39 | GenericDef::Trait(inner) => inner.resolver(db), | ||
40 | GenericDef::TypeAlias(inner) => inner.resolver(db), | ||
41 | GenericDef::ImplBlock(inner) => inner.resolver(db), | ||
42 | GenericDef::EnumVariant(inner) => inner.parent_enum(db).resolver(db), | ||
43 | GenericDef::Const(inner) => inner.resolver(db), | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | |||
48 | impl From<Container> for GenericDef { | 34 | impl From<Container> for GenericDef { |
49 | fn from(c: Container) -> Self { | 35 | fn from(c: Container) -> Self { |
50 | match c { | 36 | match c { |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 492d964a4..964a3da8c 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::ast::{self}; | |||
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 7 | db::{AstDatabase, DefDatabase, HirDatabase}, |
8 | resolve::Resolver, | 8 | resolve::HasResolver, |
9 | ty::Ty, | 9 | ty::Ty, |
10 | AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef, | 10 | AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef, |
11 | }; | 11 | }; |
@@ -50,12 +50,4 @@ impl ImplBlock { | |||
50 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { | 50 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { |
51 | Crate { crate_id: self.module(db).id.krate } | 51 | Crate { crate_id: self.module(db).id.krate } |
52 | } | 52 | } |
53 | |||
54 | pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
55 | let r = self.module(db).resolver(db); | ||
56 | // add generic params, if present | ||
57 | let r = r.push_generic_params_scope(db, self.into()); | ||
58 | let r = r.push_impl_block_scope(self); | ||
59 | r | ||
60 | } | ||
61 | } | 53 | } |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index e5e768be9..b8e1b4dad 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -15,8 +15,8 @@ use crate::{ | |||
15 | db::{DefDatabase, HirDatabase}, | 15 | db::{DefDatabase, HirDatabase}, |
16 | expr::{ExprScopes, PatId, ScopeId}, | 16 | expr::{ExprScopes, PatId, ScopeId}, |
17 | generics::{GenericParams, HasGenericParams}, | 17 | generics::{GenericParams, HasGenericParams}, |
18 | Adt, Const, DefWithBody, Enum, EnumVariant, Function, GenericDef, ImplBlock, Local, MacroDef, | 18 | Adt, Const, Container, DefWithBody, Enum, EnumVariant, Function, GenericDef, ImplBlock, Local, |
19 | ModuleDef, PerNs, Static, Struct, Trait, TypeAlias, | 19 | MacroDef, Module, ModuleDef, PerNs, Static, Struct, Trait, TypeAlias, Union, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | #[derive(Debug, Clone, Default)] | 22 | #[derive(Debug, Clone, Default)] |
@@ -486,3 +486,130 @@ impl Scope { | |||
486 | } | 486 | } |
487 | } | 487 | } |
488 | } | 488 | } |
489 | |||
490 | pub(crate) trait HasResolver { | ||
491 | /// Builds a resolver for type references inside this def. | ||
492 | fn resolver(self, db: &impl DefDatabase) -> Resolver; | ||
493 | } | ||
494 | |||
495 | impl HasResolver for Module { | ||
496 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
497 | let def_map = db.crate_def_map(self.id.krate); | ||
498 | Resolver::default().push_module_scope(def_map, self.id.module_id) | ||
499 | } | ||
500 | } | ||
501 | |||
502 | impl HasResolver for Trait { | ||
503 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
504 | self.module(db).resolver(db).push_generic_params_scope(db, self.into()) | ||
505 | } | ||
506 | } | ||
507 | |||
508 | impl HasResolver for Struct { | ||
509 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
510 | self.module(db) | ||
511 | .resolver(db) | ||
512 | .push_generic_params_scope(db, self.into()) | ||
513 | .push_scope(Scope::AdtScope(self.into())) | ||
514 | } | ||
515 | } | ||
516 | |||
517 | impl HasResolver for Union { | ||
518 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
519 | self.module(db) | ||
520 | .resolver(db) | ||
521 | .push_generic_params_scope(db, self.into()) | ||
522 | .push_scope(Scope::AdtScope(self.into())) | ||
523 | } | ||
524 | } | ||
525 | |||
526 | impl HasResolver for Enum { | ||
527 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
528 | self.module(db) | ||
529 | .resolver(db) | ||
530 | .push_generic_params_scope(db, self.into()) | ||
531 | .push_scope(Scope::AdtScope(self.into())) | ||
532 | } | ||
533 | } | ||
534 | |||
535 | impl HasResolver for Adt { | ||
536 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
537 | match self { | ||
538 | Adt::Struct(it) => it.resolver(db), | ||
539 | Adt::Union(it) => it.resolver(db), | ||
540 | Adt::Enum(it) => it.resolver(db), | ||
541 | } | ||
542 | } | ||
543 | } | ||
544 | |||
545 | impl HasResolver for Function { | ||
546 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
547 | self.container(db) | ||
548 | .map(|c| c.resolver(db)) | ||
549 | .unwrap_or_else(|| self.module(db).resolver(db)) | ||
550 | .push_generic_params_scope(db, self.into()) | ||
551 | } | ||
552 | } | ||
553 | |||
554 | impl HasResolver for DefWithBody { | ||
555 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
556 | match self { | ||
557 | DefWithBody::Const(c) => c.resolver(db), | ||
558 | DefWithBody::Function(f) => f.resolver(db), | ||
559 | DefWithBody::Static(s) => s.resolver(db), | ||
560 | } | ||
561 | } | ||
562 | } | ||
563 | |||
564 | impl HasResolver for Const { | ||
565 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
566 | self.container(db).map(|c| c.resolver(db)).unwrap_or_else(|| self.module(db).resolver(db)) | ||
567 | } | ||
568 | } | ||
569 | |||
570 | impl HasResolver for Static { | ||
571 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
572 | self.module(db).resolver(db) | ||
573 | } | ||
574 | } | ||
575 | |||
576 | impl HasResolver for TypeAlias { | ||
577 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
578 | self.container(db) | ||
579 | .map(|ib| ib.resolver(db)) | ||
580 | .unwrap_or_else(|| self.module(db).resolver(db)) | ||
581 | .push_generic_params_scope(db, self.into()) | ||
582 | } | ||
583 | } | ||
584 | |||
585 | impl HasResolver for Container { | ||
586 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
587 | match self { | ||
588 | Container::Trait(trait_) => trait_.resolver(db), | ||
589 | Container::ImplBlock(impl_block) => impl_block.resolver(db), | ||
590 | } | ||
591 | } | ||
592 | } | ||
593 | |||
594 | impl HasResolver for GenericDef { | ||
595 | fn resolver(self, db: &impl DefDatabase) -> crate::Resolver { | ||
596 | match self { | ||
597 | GenericDef::Function(inner) => inner.resolver(db), | ||
598 | GenericDef::Adt(adt) => adt.resolver(db), | ||
599 | GenericDef::Trait(inner) => inner.resolver(db), | ||
600 | GenericDef::TypeAlias(inner) => inner.resolver(db), | ||
601 | GenericDef::ImplBlock(inner) => inner.resolver(db), | ||
602 | GenericDef::EnumVariant(inner) => inner.parent_enum(db).resolver(db), | ||
603 | GenericDef::Const(inner) => inner.resolver(db), | ||
604 | } | ||
605 | } | ||
606 | } | ||
607 | |||
608 | impl HasResolver for ImplBlock { | ||
609 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
610 | self.module(db) | ||
611 | .resolver(db) | ||
612 | .push_generic_params_scope(db, self.into()) | ||
613 | .push_impl_block_scope(self) | ||
614 | } | ||
615 | } | ||
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index fd9994098..727310f06 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -23,7 +23,7 @@ use crate::{ | |||
23 | db::HirDatabase, | 23 | db::HirDatabase, |
24 | expr::{self, BodySourceMap, ExprScopes, ScopeId}, | 24 | expr::{self, BodySourceMap, ExprScopes, ScopeId}, |
25 | ids::LocationCtx, | 25 | ids::LocationCtx, |
26 | resolve::{ScopeDef, TypeNs, ValueNs}, | 26 | resolve::{HasResolver, ScopeDef, TypeNs, ValueNs}, |
27 | ty::method_resolution::{self, implements_trait}, | 27 | ty::method_resolution::{self, implements_trait}, |
28 | AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody, | 28 | AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody, |
29 | HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, | 29 | HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 092bc3a3f..7f9e81d64 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -40,7 +40,7 @@ use crate::{ | |||
40 | code_model::TypeAlias, | 40 | code_model::TypeAlias, |
41 | db::HirDatabase, | 41 | db::HirDatabase, |
42 | expr::{BindingAnnotation, Body, ExprId, PatId}, | 42 | expr::{BindingAnnotation, Body, ExprId, PatId}, |
43 | resolve::{Resolver, TypeNs}, | 43 | resolve::{HasResolver, Resolver, TypeNs}, |
44 | ty::infer::diagnostics::InferenceDiagnostic, | 44 | ty::infer::diagnostics::InferenceDiagnostic, |
45 | Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, | 45 | Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, |
46 | StructField, VariantDef, | 46 | StructField, VariantDef, |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 91e60b5ab..397ee7d5f 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -22,7 +22,7 @@ use crate::{ | |||
22 | db::HirDatabase, | 22 | db::HirDatabase, |
23 | generics::HasGenericParams, | 23 | generics::HasGenericParams, |
24 | generics::{GenericDef, WherePredicate}, | 24 | generics::{GenericDef, WherePredicate}, |
25 | resolve::{Resolver, TypeNs}, | 25 | resolve::{HasResolver, Resolver, TypeNs}, |
26 | ty::{ | 26 | ty::{ |
27 | primitive::{FloatTy, IntTy, Uncertain}, | 27 | primitive::{FloatTy, IntTy, Uncertain}, |
28 | Adt, | 28 | Adt, |