From 251ef93ac3bbb138a2eedf6090f2f56f1a15d898 Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 10 Sep 2020 20:01:23 +0800 Subject: Implement async blocks --- crates/hir_ty/src/infer/expr.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index a2f849d02..0a141b9cb 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -17,8 +17,8 @@ use crate::{ autoderef, method_resolution, op, traits::{FnTrait, InEnvironment}, utils::{generics, variant_data, Generics}, - ApplicationTy, Binders, CallableDefId, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, - TraitRef, Ty, TypeCtor, + ApplicationTy, Binders, CallableDefId, InferTy, IntTy, Mutability, Obligation, OpaqueTyId, + Rawness, Substs, TraitRef, Ty, TypeCtor, }; use super::{ @@ -146,6 +146,13 @@ impl<'a> InferenceContext<'a> { // FIXME should be std::result::Result<{inner}, _> Ty::Unknown } + Expr::Async { body } => { + // Use the first type parameter as the output type of future. + // existenail type AsyncBlockImplTrait: Future + let inner_ty = self.infer_expr(*body, &Expectation::none()); + let opaque_ty_id = OpaqueTyId::AsyncBlockTypeImplTrait(self.owner, *body); + Ty::apply_one(TypeCtor::OpaqueType(opaque_ty_id), inner_ty) + } Expr::Loop { body, label } => { self.breakables.push(BreakableContext { may_break: false, -- cgit v1.2.3