mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
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 <arnaud.golfouse@free.fr>
This commit is contained in:
commit
b99b14311c
1 changed files with 12 additions and 0 deletions
|
@ -743,6 +743,18 @@ impl Function {
|
||||||
db.function_data(self.id).name.clone()
|
db.function_data(self.id).name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get this function's return type
|
||||||
|
pub fn ret_type(self, db: &dyn HirDatabase) -> Type {
|
||||||
|
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);
|
||||||
|
Type {
|
||||||
|
krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate,
|
||||||
|
ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
|
pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
|
||||||
if !db.function_data(self.id).has_self_param {
|
if !db.function_data(self.id).has_self_param {
|
||||||
return None;
|
return None;
|
||||||
|
|
Loading…
Reference in a new issue