diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-20 19:23:31 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-20 19:23:31 +0000 |
commit | 2cb2fb1a4807b4e53390c5f88c85106454706b64 (patch) | |
tree | f081f89d08f2edf7859c6d3f9738f507c1dca2d6 /crates/ra_hir | |
parent | 6983afdea9f41e58d7ebbd15012532cd3935451f (diff) | |
parent | 63f327be67a8e6e0786cc089fba5f9b3f53c5bd6 (diff) |
Merge #2332
2332: Add HasResolver trait r=matklad a=matklad
bors merge
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 121 | ||||
-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 | 104 | ||||
-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, 119 insertions, 141 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9b6276b51..a132d128b 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)] |
@@ -465,24 +432,17 @@ impl Adt { | |||
465 | } | 432 | } |
466 | } | 433 | } |
467 | 434 | ||
468 | pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | 435 | pub fn module(self, db: &impl DefDatabase) -> Module { |
469 | Some( | ||
470 | match self { | ||
471 | Adt::Struct(s) => s.module(db), | ||
472 | Adt::Union(s) => s.module(db), | ||
473 | Adt::Enum(e) => e.module(db), | ||
474 | } | ||
475 | .krate(), | ||
476 | ) | ||
477 | } | ||
478 | |||
479 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
480 | match self { | 436 | match self { |
481 | Adt::Struct(it) => it.resolver(db), | 437 | Adt::Struct(s) => s.module(db), |
482 | Adt::Union(it) => it.resolver(db), | 438 | Adt::Union(s) => s.module(db), |
483 | Adt::Enum(it) => it.resolver(db), | 439 | Adt::Enum(e) => e.module(db), |
484 | } | 440 | } |
485 | } | 441 | } |
442 | |||
443 | pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | ||
444 | Some(self.module(db).krate()) | ||
445 | } | ||
486 | } | 446 | } |
487 | 447 | ||
488 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 448 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -533,15 +493,6 @@ pub enum DefWithBody { | |||
533 | impl_froms!(DefWithBody: Function, Const, Static); | 493 | impl_froms!(DefWithBody: Function, Const, Static); |
534 | 494 | ||
535 | impl DefWithBody { | 495 | 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> { | 496 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { |
546 | match self { | 497 | match self { |
547 | DefWithBody::Const(c) => c.krate(db), | 498 | DefWithBody::Const(c) => c.krate(db), |
@@ -738,15 +689,6 @@ impl Function { | |||
738 | } | 689 | } |
739 | } | 690 | } |
740 | 691 | ||
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) { | 692 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { |
751 | let infer = self.infer(db); | 693 | let infer = self.infer(db); |
752 | infer.add_diagnostics(db, self, sink); | 694 | infer.add_diagnostics(db, self, sink); |
@@ -804,17 +746,6 @@ impl Const { | |||
804 | ContainerId::ModuleId(_) => None, | 746 | ContainerId::ModuleId(_) => None, |
805 | } | 747 | } |
806 | } | 748 | } |
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 | } | 749 | } |
819 | 750 | ||
820 | #[derive(Debug, Clone, PartialEq, Eq)] | 751 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -874,12 +805,6 @@ impl Static { | |||
874 | db.static_data(self) | 805 | db.static_data(self) |
875 | } | 806 | } |
876 | 807 | ||
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> { | 808 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
884 | db.infer(self.into()) | 809 | db.infer(self.into()) |
885 | } | 810 | } |
@@ -975,12 +900,6 @@ impl Trait { | |||
975 | pub fn is_auto(self, db: &impl DefDatabase) -> bool { | 900 | pub fn is_auto(self, db: &impl DefDatabase) -> bool { |
976 | self.trait_data(db).auto | 901 | self.trait_data(db).auto |
977 | } | 902 | } |
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 | } | 903 | } |
985 | 904 | ||
986 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 905 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -1032,17 +951,6 @@ impl TypeAlias { | |||
1032 | pub fn name(self, db: &impl DefDatabase) -> Name { | 951 | pub fn name(self, db: &impl DefDatabase) -> Name { |
1033 | db.type_alias_data(self).name.clone() | 952 | db.type_alias_data(self).name.clone() |
1034 | } | 953 | } |
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 | } | 954 | } |
1047 | 955 | ||
1048 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 956 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -1058,15 +966,6 @@ pub enum Container { | |||
1058 | } | 966 | } |
1059 | impl_froms!(Container: Trait, ImplBlock); | 967 | impl_froms!(Container: Trait, ImplBlock); |
1060 | 968 | ||
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)] | 969 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
1071 | pub enum AssocItem { | 970 | pub enum AssocItem { |
1072 | Function(Function), | 971 | 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..eca8e0596 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, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | #[derive(Debug, Clone, Default)] | 22 | #[derive(Debug, Clone, Default)] |
@@ -486,3 +486,103 @@ 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<T: Into<Adt>> HasResolver for T { | ||
509 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
510 | let def = self.into(); | ||
511 | def.module(db) | ||
512 | .resolver(db) | ||
513 | .push_generic_params_scope(db, def.into()) | ||
514 | .push_scope(Scope::AdtScope(def)) | ||
515 | } | ||
516 | } | ||
517 | |||
518 | impl HasResolver for Function { | ||
519 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
520 | self.container(db) | ||
521 | .map(|c| c.resolver(db)) | ||
522 | .unwrap_or_else(|| self.module(db).resolver(db)) | ||
523 | .push_generic_params_scope(db, self.into()) | ||
524 | } | ||
525 | } | ||
526 | |||
527 | impl HasResolver for DefWithBody { | ||
528 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
529 | match self { | ||
530 | DefWithBody::Const(c) => c.resolver(db), | ||
531 | DefWithBody::Function(f) => f.resolver(db), | ||
532 | DefWithBody::Static(s) => s.resolver(db), | ||
533 | } | ||
534 | } | ||
535 | } | ||
536 | |||
537 | impl HasResolver for Const { | ||
538 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
539 | self.container(db).map(|c| c.resolver(db)).unwrap_or_else(|| self.module(db).resolver(db)) | ||
540 | } | ||
541 | } | ||
542 | |||
543 | impl HasResolver for Static { | ||
544 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
545 | self.module(db).resolver(db) | ||
546 | } | ||
547 | } | ||
548 | |||
549 | impl HasResolver for TypeAlias { | ||
550 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
551 | self.container(db) | ||
552 | .map(|ib| ib.resolver(db)) | ||
553 | .unwrap_or_else(|| self.module(db).resolver(db)) | ||
554 | .push_generic_params_scope(db, self.into()) | ||
555 | } | ||
556 | } | ||
557 | |||
558 | impl HasResolver for Container { | ||
559 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
560 | match self { | ||
561 | Container::Trait(trait_) => trait_.resolver(db), | ||
562 | Container::ImplBlock(impl_block) => impl_block.resolver(db), | ||
563 | } | ||
564 | } | ||
565 | } | ||
566 | |||
567 | impl HasResolver for GenericDef { | ||
568 | fn resolver(self, db: &impl DefDatabase) -> crate::Resolver { | ||
569 | match self { | ||
570 | GenericDef::Function(inner) => inner.resolver(db), | ||
571 | GenericDef::Adt(adt) => adt.resolver(db), | ||
572 | GenericDef::Trait(inner) => inner.resolver(db), | ||
573 | GenericDef::TypeAlias(inner) => inner.resolver(db), | ||
574 | GenericDef::ImplBlock(inner) => inner.resolver(db), | ||
575 | GenericDef::EnumVariant(inner) => inner.parent_enum(db).resolver(db), | ||
576 | GenericDef::Const(inner) => inner.resolver(db), | ||
577 | } | ||
578 | } | ||
579 | } | ||
580 | |||
581 | impl HasResolver for ImplBlock { | ||
582 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
583 | self.module(db) | ||
584 | .resolver(db) | ||
585 | .push_generic_params_scope(db, self.into()) | ||
586 | .push_impl_block_scope(self) | ||
587 | } | ||
588 | } | ||
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, |