aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-20 19:00:57 +0000
committerAleksey Kladov <[email protected]>2019-11-20 19:22:32 +0000
commit1cead415100c35097d5ea68cf58b9485fe306dc2 (patch)
tree6f5710a5612ce2a0e383bee9b21e8525746fc456
parent6241cf9a598b19cbd6c8c41c3743f8d56adafd2b (diff)
Simplify
-rw-r--r--crates/ra_hir/src/code_model.rs17
-rw-r--r--crates/ra_hir/src/resolve.rs39
2 files changed, 15 insertions, 41 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index c5539e076..a132d128b 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -432,15 +432,16 @@ impl Adt {
432 } 432 }
433 } 433 }
434 434
435 pub fn module(self, db: &impl DefDatabase) -> Module {
436 match self {
437 Adt::Struct(s) => s.module(db),
438 Adt::Union(s) => s.module(db),
439 Adt::Enum(e) => e.module(db),
440 }
441 }
442
435 pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> { 443 pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
436 Some( 444 Some(self.module(db).krate())
437 match self {
438 Adt::Struct(s) => s.module(db),
439 Adt::Union(s) => s.module(db),
440 Adt::Enum(e) => e.module(db),
441 }
442 .krate(),
443 )
444 } 445 }
445} 446}
446 447
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index b8e1b4dad..eca8e0596 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -16,7 +16,7 @@ use crate::{
16 expr::{ExprScopes, PatId, ScopeId}, 16 expr::{ExprScopes, PatId, ScopeId},
17 generics::{GenericParams, HasGenericParams}, 17 generics::{GenericParams, HasGenericParams},
18 Adt, Const, Container, DefWithBody, Enum, EnumVariant, Function, GenericDef, ImplBlock, Local, 18 Adt, Const, Container, DefWithBody, Enum, EnumVariant, Function, GenericDef, ImplBlock, Local,
19 MacroDef, Module, ModuleDef, PerNs, Static, Struct, Trait, TypeAlias, Union, 19 MacroDef, Module, ModuleDef, PerNs, Static, Struct, Trait, TypeAlias,
20}; 20};
21 21
22#[derive(Debug, Clone, Default)] 22#[derive(Debug, Clone, Default)]
@@ -505,40 +505,13 @@ impl HasResolver for Trait {
505 } 505 }
506} 506}
507 507
508impl HasResolver for Struct { 508impl<T: Into<Adt>> HasResolver for T {
509 fn resolver(self, db: &impl DefDatabase) -> Resolver { 509 fn resolver(self, db: &impl DefDatabase) -> Resolver {
510 self.module(db) 510 let def = self.into();
511 .resolver(db) 511 def.module(db)
512 .push_generic_params_scope(db, self.into())
513 .push_scope(Scope::AdtScope(self.into()))
514 }
515}
516
517impl 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
526impl HasResolver for Enum {
527 fn resolver(self, db: &impl DefDatabase) -> Resolver {
528 self.module(db)
529 .resolver(db) 512 .resolver(db)
530 .push_generic_params_scope(db, self.into()) 513 .push_generic_params_scope(db, def.into())
531 .push_scope(Scope::AdtScope(self.into())) 514 .push_scope(Scope::AdtScope(def))
532 }
533}
534
535impl 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 } 515 }
543} 516}
544 517