From 54d60fdee9a49e2081837cc6445c61dec0b303af Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 29 May 2021 18:16:20 +0200 Subject: hir_ty: use async ret type for inference inside async bodies --- crates/hir_def/src/data.rs | 2 ++ crates/hir_def/src/item_tree.rs | 1 + crates/hir_def/src/item_tree/lower.rs | 8 +++++--- crates/hir_def/src/item_tree/pretty.rs | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index a04f73352..d2bb381be 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -22,6 +22,7 @@ pub struct FunctionData { pub name: Name, pub params: Vec>, pub ret_type: Interned, + pub async_ret_type: Option>, pub attrs: Attrs, pub visibility: RawVisibility, pub abi: Option>, @@ -63,6 +64,7 @@ impl FunctionData { }) .collect(), ret_type: func.ret_type.clone(), + async_ret_type: func.async_ret_type.clone(), attrs: item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()), visibility: item_tree[func.visibility].clone(), abi: func.abi.clone(), diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index c4d20c416..227337a8d 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -580,6 +580,7 @@ pub struct Function { pub abi: Option>, pub params: IdRange, pub ret_type: Interned, + pub async_ret_type: Option>, pub ast_id: FileAstId, pub(crate) flags: FnFlags, } diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index b83adec46..6208facd5 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -356,12 +356,13 @@ impl<'a> Ctx<'a> { _ => TypeRef::unit(), }; - let ret_type = if func.async_token().is_some() { + let (ret_type, async_ret_type) = if func.async_token().is_some() { + let async_ret_type = ret_type.clone(); let future_impl = desugar_future_path(ret_type); let ty_bound = Interned::new(TypeBound::Path(future_impl)); - TypeRef::ImplTrait(vec![ty_bound]) + (TypeRef::ImplTrait(vec![ty_bound]), Some(async_ret_type)) } else { - ret_type + (ret_type, None) }; let abi = func.abi().map(lower_abi); @@ -395,6 +396,7 @@ impl<'a> Ctx<'a> { abi, params, ret_type: Interned::new(ret_type), + async_ret_type: async_ret_type.map(Interned::new), ast_id, flags, }; diff --git a/crates/hir_def/src/item_tree/pretty.rs b/crates/hir_def/src/item_tree/pretty.rs index d1ee697cb..cc9944a22 100644 --- a/crates/hir_def/src/item_tree/pretty.rs +++ b/crates/hir_def/src/item_tree/pretty.rs @@ -235,6 +235,7 @@ impl<'a> Printer<'a> { abi, params, ret_type, + async_ret_type: _, ast_id: _, flags, } = &self.tree[it]; -- cgit v1.2.3