aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs62
-rw-r--r--crates/ra_hir/src/lib.rs2
2 files changed, 4 insertions, 60 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 7850ea9a7..8dbc0d667 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -11,9 +11,9 @@ use hir_def::{
11 per_ns::PerNs, 11 per_ns::PerNs,
12 resolver::HasResolver, 12 resolver::HasResolver,
13 type_ref::{Mutability, TypeRef}, 13 type_ref::{Mutability, TypeRef},
14 AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, 14 AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId,
15 LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, 15 LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId,
16 StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, 16 TraitId, TypeAliasId, TypeParamId, UnionId,
17}; 17};
18use hir_expand::{ 18use hir_expand::{
19 diagnostics::DiagnosticSink, 19 diagnostics::DiagnosticSink,
@@ -529,30 +529,6 @@ impl Const {
529 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 529 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
530 db.const_data(self.id).name.clone() 530 db.const_data(self.id).name.clone()
531 } 531 }
532
533 /// The containing impl block, if this is a type alias.
534 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
535 match self.container(db) {
536 Some(Container::ImplBlock(it)) => Some(it),
537 _ => None,
538 }
539 }
540
541 /// The containing trait, if this is a trait type alias definition.
542 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
543 match self.container(db) {
544 Some(Container::Trait(it)) => Some(it),
545 _ => None,
546 }
547 }
548
549 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
550 match self.id.lookup(db).container {
551 ContainerId::TraitId(it) => Some(Container::Trait(it.into())),
552 ContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())),
553 ContainerId::ModuleId(_) => None,
554 }
555 }
556} 532}
557 533
558#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 534#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -612,30 +588,6 @@ impl TypeAlias {
612 Some(self.module(db).krate()) 588 Some(self.module(db).krate())
613 } 589 }
614 590
615 /// The containing impl block, if this is a type alias.
616 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
617 match self.container(db) {
618 Some(Container::ImplBlock(it)) => Some(it),
619 _ => None,
620 }
621 }
622
623 /// The containing trait, if this is a trait type alias definition.
624 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
625 match self.container(db) {
626 Some(Container::Trait(it)) => Some(it),
627 _ => None,
628 }
629 }
630
631 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
632 match self.id.lookup(db).container {
633 ContainerId::TraitId(it) => Some(Container::Trait(it.into())),
634 ContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())),
635 ContainerId::ModuleId(_) => None,
636 }
637 }
638
639 pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> { 591 pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> {
640 db.type_alias_data(self.id).type_ref.clone() 592 db.type_alias_data(self.id).type_ref.clone()
641 } 593 }
@@ -654,14 +606,6 @@ pub struct MacroDef {
654 pub(crate) id: MacroDefId, 606 pub(crate) id: MacroDefId,
655} 607}
656 608
657impl MacroDef {}
658
659pub enum Container {
660 Trait(Trait),
661 ImplBlock(ImplBlock),
662}
663impl_froms!(Container: Trait, ImplBlock);
664
665#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 609#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
666pub enum AssocItem { 610pub enum AssocItem {
667 Function(Function), 611 Function(Function),
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 2e52a1f5c..7f9aef770 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -39,7 +39,7 @@ mod from_source;
39 39
40pub use crate::{ 40pub use crate::{
41 code_model::{ 41 code_model::{
42 Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, DefWithBody, Docs, Enum, 42 Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum,
43 EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Import, Local, 43 EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Import, Local,
44 MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias, 44 MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
45 TypeParam, Union, VariantDef, 45 TypeParam, Union, VariantDef,