diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-04 21:07:50 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-04 21:07:50 +0000 |
commit | b99b14311c57f6e5f1d50d1868513c4459e33328 (patch) | |
tree | 70379a97f2d5812fb8f8015bffcfa7cdd451e050 /crates/hir | |
parent | 550c49657eabbe7583819c7e19c94eaa7d2c589e (diff) | |
parent | 052404565ea495b32956373e18d807a8cde68ceb (diff) |
Merge #7160
7160: Get `hir::Function` return type r=flodiebold a=arnaudgolfouse
Hello !
As said in #7158, I noticed that `hir::Function` has no direct way of getting the return type, so this PR adds this functionality.
Co-authored-by: Arnaud <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 071e553a8..1a4aa78fb 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 | /// Get this function's return type | ||
747 | pub fn ret_type(self, db: &dyn HirDatabase) -> Type { | ||
748 | let resolver = self.id.resolver(db.upcast()); | ||
749 | let ret_type = &db.function_data(self.id).ret_type; | ||
750 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); | ||
751 | let environment = TraitEnvironment::lower(db, &resolver); | ||
752 | Type { | ||
753 | krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, | ||
754 | ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment }, | ||
755 | } | ||
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; |