Skip to content

Commit 44e801a

Browse files
committed
thread down the body so we can check if this is an async fn body
1 parent c845f3d commit 44e801a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/librustc_typeck/check/closure.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
337337
) -> ClosureSignatures<'tcx> {
338338
debug!("sig_of_closure_no_expectation()");
339339

340-
let bound_sig = self.supplied_sig_of_closure(expr_def_id, decl);
340+
let bound_sig = self.supplied_sig_of_closure(expr_def_id, decl, body);
341341

342342
self.closure_sigs(expr_def_id, body, bound_sig)
343343
}
@@ -490,7 +490,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
490490
//
491491
// (See comment on `sig_of_closure_with_expectation` for the
492492
// meaning of these letters.)
493-
let supplied_sig = self.supplied_sig_of_closure(expr_def_id, decl);
493+
let supplied_sig = self.supplied_sig_of_closure(expr_def_id, decl, body);
494494

495495
debug!(
496496
"check_supplied_sig_against_expectation: supplied_sig={:?}",
@@ -591,14 +591,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
591591
&self,
592592
expr_def_id: DefId,
593593
decl: &hir::FnDecl,
594+
body: &hir::Body,
594595
) -> ty::PolyFnSig<'tcx> {
595596
let astconv: &dyn AstConv<'_> = self;
596597

597598
// First, convert the types that the user supplied (if any).
598599
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
599600
let supplied_return = match decl.output {
600601
hir::Return(ref output) => astconv.ast_ty_to_ty(&output),
601-
hir::DefaultReturn(_) => astconv.ty_infer(None, decl.output.span()),
602+
hir::DefaultReturn(_) => match body.generator_kind {
603+
// In the case of the async block that we create for a function body,
604+
// we expect the return type of the block to match that of the enclosing
605+
// function.
606+
Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn)) => {
607+
debug!("supplied_sig_of_closure: closure is async fn body");
608+
609+
// FIXME
610+
astconv.ty_infer(None, decl.output.span())
611+
}
612+
613+
_ => astconv.ty_infer(None, decl.output.span()),
614+
}
602615
};
603616

604617
let result = ty::Binder::bind(self.tcx.mk_fn_sig(

0 commit comments

Comments
 (0)