Implement async blocks

This commit is contained in:
oxalica 2020-09-10 20:01:23 +08:00
parent 0275b08d15
commit 251ef93ac3
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
11 changed files with 248 additions and 55 deletions

View file

@ -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<InnerType>: Future<Output = InnerType>
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,