Skip to content

Commit f7d0a8e

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 a807032 commit f7d0a8e

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

617627
_ => astconv.ty_infer(None, decl.output.span()),
@@ -646,7 +656,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
646656
fn deduce_future_output_from_obligations(
647657
&self,
648658
expr_def_id: DefId,
649-
) -> Ty<'tcx> {
659+
) -> Option<Ty<'tcx>> {
650660
debug!("deduce_future_output_from_obligations(expr_def_id={:?})", expr_def_id);
651661

652662
let ret_coercion =
@@ -689,8 +699,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
689699
} else {
690700
None
691701
}
692-
})
693-
.unwrap();
702+
});
694703

695704
debug!("deduce_future_output_from_obligations: output_ty={:?}", output_ty);
696705
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)