mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 20:03:37 +00:00
Make it possible to retrieve hir::Function
's return type
This is done by adding a `ret_type` method to `hir::Function`. I followed `assoc_fn_params` convention by creating a new `RetType` type, that contains the actual return type accessible via a `ty` method.
This commit is contained in:
parent
0708bfeb72
commit
a6dc7cf36d
@ -743,6 +743,18 @@ impl Function {
|
|||||||
db.function_data(self.id).name.clone()
|
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<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;
|
||||||
@ -826,6 +838,17 @@ impl From<Mutability> for Access {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RetType {
|
||||||
|
ty: Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RetType {
|
||||||
|
pub fn ty(&self) -> &Type {
|
||||||
|
&self.ty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Param {
|
pub struct Param {
|
||||||
ty: Type,
|
ty: Type,
|
||||||
|
Loading…
Reference in New Issue
Block a user