diff options
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 071e553a8..e783e0aba 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -743,6 +743,18 @@ impl Function { | |||
743 | db.function_data(self.id).name.clone() | 743 | db.function_data(self.id).name.clone() |
744 | } | 744 | } |
745 | 745 | ||
746 | pub fn ret_type(self, db: &dyn HirDatabase) -> RetType { | ||
747 | let resolver = self.id.resolver(db.upcast()); | ||
748 | let ret_type = &db.function_data(self.id).ret_type; | ||
749 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); | ||
750 | let environment = TraitEnvironment::lower(db, &resolver); | ||
751 | let ty = Type { | ||
752 | krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, | ||
753 | ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment }, | ||
754 | }; | ||
755 | RetType { ty } | ||
756 | } | ||
757 | |||
746 | pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { | 758 | pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { |
747 | if !db.function_data(self.id).has_self_param { | 759 | if !db.function_data(self.id).has_self_param { |
748 | return None; | 760 | return None; |
@@ -827,6 +839,17 @@ impl From<Mutability> for Access { | |||
827 | } | 839 | } |
828 | 840 | ||
829 | #[derive(Debug)] | 841 | #[derive(Debug)] |
842 | pub struct RetType { | ||
843 | ty: Type, | ||
844 | } | ||
845 | |||
846 | impl RetType { | ||
847 | pub fn ty(&self) -> &Type { | ||
848 | &self.ty | ||
849 | } | ||
850 | } | ||
851 | |||
852 | #[derive(Debug)] | ||
830 | pub struct Param { | 853 | pub struct Param { |
831 | ty: Type, | 854 | ty: Type, |
832 | } | 855 | } |