Skip to content

Commit 48fff6f

Browse files
committed
don't assume we can *always* find a return type hint in async fn
In particular, we sometimes cannot if there is an earlier error.
1 parent d4f7f97 commit 48fff6f

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/librustc_typeck/check/closure.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
611611
Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn)) => {
612612
debug!("supplied_sig_of_closure: closure is async fn body");
613613
self.deduce_future_output_from_obligations(expr_def_id)
614+
.unwrap_or_else(|| {
615+
// AFAIK, deducing the future output
616+
// always succeeds *except* in error cases
617+
// like #65159. I'd like to return Error
618+
// here, but I can't because I can't
619+
// easily (and locally) prove that we
620+
// *have* reported an
621+
// error. --nikomatsakis
622+
astconv.ty_infer(None, decl.output.span())
623+
})
614624
}
615625

616626
_ => astconv.ty_infer(None, decl.output.span()),
@@ -645,7 +655,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
645655
fn deduce_future_output_from_obligations(
646656
&self,
647657
expr_def_id: DefId,
648-
) -> Ty<'tcx> {
658+
) -> Option<Ty<'tcx>> {
649659
debug!("deduce_future_output_from_obligations(expr_def_id={:?})", expr_def_id);
650660

651661
let ret_coercion =
@@ -688,8 +698,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
688698
} else {
689699
None
690700
}
691-
})
692-
.unwrap();
701+
});
693702

694703
debug!("deduce_future_output_from_obligations: output_ty={:?}", output_ty);
695704
output_ty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for #65159. We used to ICE.
2+
//
3+
// edition:2018
4+
5+
async fn copy() -> Result<()> //~ ERROR wrong number of type arguments
6+
{
7+
Ok(())
8+
}
9+
10+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0107]: wrong number of type arguments: expected 2, found 1
2+
--> $DIR/issue-65159.rs:5:20
3+
|
4+
LL | async fn copy() -> Result<()>
5+
| ^^^^^^^^^^ expected 2 type arguments
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)