diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/code_model.rs | 39 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 4 |
2 files changed, 3 insertions, 40 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 9989b9b56..650b4fa40 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -35,7 +35,7 @@ use hir_ty::{ | |||
35 | traits::SolutionVariables, | 35 | traits::SolutionVariables, |
36 | ApplicationTy, BoundVar, CallableDefId, Canonical, DebruijnIndex, FnSig, GenericPredicate, | 36 | ApplicationTy, BoundVar, CallableDefId, Canonical, DebruijnIndex, FnSig, GenericPredicate, |
37 | InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, Ty, | 37 | InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, Ty, |
38 | TyDefId, TyKind, TypeCtor, TyLoweringContext, | 38 | TyDefId, TyKind, TypeCtor, |
39 | }; | 39 | }; |
40 | use rustc_hash::FxHashSet; | 40 | use rustc_hash::FxHashSet; |
41 | use stdx::impl_from; | 41 | use stdx::impl_from; |
@@ -186,15 +186,6 @@ impl_from!( | |||
186 | for ModuleDef | 186 | for ModuleDef |
187 | ); | 187 | ); |
188 | 188 | ||
189 | impl From<MethodOwner> for ModuleDef { | ||
190 | fn from(mowner: MethodOwner) -> Self { | ||
191 | match mowner { | ||
192 | MethodOwner::Trait(t) => t.into(), | ||
193 | MethodOwner::Adt(t) => t.into(), | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | |||
198 | impl From<VariantDef> for ModuleDef { | 189 | impl From<VariantDef> for ModuleDef { |
199 | fn from(var: VariantDef) -> Self { | 190 | fn from(var: VariantDef) -> Self { |
200 | match var { | 191 | match var { |
@@ -778,36 +769,8 @@ impl Function { | |||
778 | pub fn has_body(self, db: &dyn HirDatabase) -> bool { | 769 | pub fn has_body(self, db: &dyn HirDatabase) -> bool { |
779 | db.function_data(self.id).has_body | 770 | db.function_data(self.id).has_body |
780 | } | 771 | } |
781 | |||
782 | /// If this function is a method, the trait or type where it is declared. | ||
783 | pub fn method_owner(self, db: &dyn HirDatabase) -> Option<MethodOwner> { | ||
784 | match self.as_assoc_item(db).map(|assoc| assoc.container(db)) { | ||
785 | Some(AssocItemContainer::Trait(t)) => Some(t.into()), | ||
786 | Some(AssocItemContainer::ImplDef(imp)) => { | ||
787 | let resolver = ModuleId::from(imp.module(db)).resolver(db.upcast()); | ||
788 | let ctx = TyLoweringContext::new(db, &resolver); | ||
789 | let adt = Ty::from_hir( | ||
790 | &ctx, | ||
791 | &imp.target_trait(db).unwrap_or_else(|| imp.target_type(db)), | ||
792 | ) | ||
793 | .as_adt() | ||
794 | .map(|t| t.0) | ||
795 | .unwrap(); | ||
796 | Some(Adt::from(adt).into()) | ||
797 | } | ||
798 | None => None, | ||
799 | } | ||
800 | } | ||
801 | } | 772 | } |
802 | 773 | ||
803 | #[derive(Debug)] | ||
804 | pub enum MethodOwner { | ||
805 | Trait(Trait), | ||
806 | Adt(Adt), | ||
807 | } | ||
808 | |||
809 | impl_from!(Trait, Adt for MethodOwner); | ||
810 | |||
811 | // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. | 774 | // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. |
812 | pub enum Access { | 775 | pub enum Access { |
813 | Shared, | 776 | Shared, |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 687abe6ca..4094a76cb 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -35,8 +35,8 @@ pub use crate::{ | |||
35 | code_model::{ | 35 | code_model::{ |
36 | Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, | 36 | Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, |
37 | Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, | 37 | Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, |
38 | GenericDef, HasVisibility, ImplDef, Local, MacroDef, MethodOwner, Module, ModuleDef, | 38 | GenericDef, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, |
39 | ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, | 39 | Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, |
40 | }, | 40 | }, |
41 | has_source::HasSource, | 41 | has_source::HasSource, |
42 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, | 42 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, |