aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r--crates/hir/src/code_model.rs39
1 files changed, 1 insertions, 38 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};
40use rustc_hash::FxHashSet; 40use rustc_hash::FxHashSet;
41use stdx::impl_from; 41use stdx::impl_from;
@@ -186,15 +186,6 @@ impl_from!(
186 for ModuleDef 186 for ModuleDef
187); 187);
188 188
189impl 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
198impl From<VariantDef> for ModuleDef { 189impl 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)]
804pub enum MethodOwner {
805 Trait(Trait),
806 Adt(Adt),
807}
808
809impl_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.
812pub enum Access { 775pub enum Access {
813 Shared, 776 Shared,