diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 071e553a88..e783e0abab 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -743,6 +743,18 @@ impl Function { db.function_data(self.id).name.clone() } + pub fn ret_type(self, db: &dyn HirDatabase) -> RetType { + let resolver = self.id.resolver(db.upcast()); + let ret_type = &db.function_data(self.id).ret_type; + let ctx = hir_ty::TyLoweringContext::new(db, &resolver); + let environment = TraitEnvironment::lower(db, &resolver); + let ty = Type { + krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, + ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment }, + }; + RetType { ty } + } + pub fn self_param(self, db: &dyn HirDatabase) -> Option { if !db.function_data(self.id).has_self_param { return None; @@ -826,6 +838,17 @@ impl From for Access { } } +#[derive(Debug)] +pub struct RetType { + ty: Type, +} + +impl RetType { + pub fn ty(&self) -> &Type { + &self.ty + } +} + #[derive(Debug)] pub struct Param { ty: Type,