about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2019-10-15 16:07:43 -0700
committerGitHub <noreply@github.com>2019-10-15 16:07:43 -0700
commitbbf4eb3fc27cc906eec1fe1932d44d18bc55ac11 (patch)
treee895e1d3f3f13424d1d00e674b1c5f6e11c0ff75 /src
parentaf3d9e57e7e487b86b113bb235b716111be48bb8 (diff)
parent48fff6f9ada2de37ad05db1084641323e7085d7d (diff)
downloadrust-bbf4eb3fc27cc906eec1fe1932d44d18bc55ac11.tar.gz
rust-bbf4eb3fc27cc906eec1fe1932d44d18bc55ac11.zip
Rollup merge of #65235 - nikomatsakis:issue-65159-async-fn-return-ice, r=cramertj
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.

Fixes #65159

r? @cramertj, who reviewed the original PR
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/closure.rs15
-rw-r--r--src/test/ui/async-await/issues/issue-65159.rs10
-rw-r--r--src/test/ui/async-await/issues/issue-65159.stderr9
3 files changed, 31 insertions, 3 deletions
diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs
index 8b97bf643e9..4f4133954cf 100644
--- a/src/librustc_typeck/check/closure.rs
+++ b/src/librustc_typeck/check/closure.rs
@@ -611,6 +611,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn)) => {
                     debug!("supplied_sig_of_closure: closure is async fn body");
                     self.deduce_future_output_from_obligations(expr_def_id)
+                        .unwrap_or_else(|| {
+                            // AFAIK, deducing the future output
+                            // always succeeds *except* in error cases
+                            // like #65159. I'd like to return Error
+                            // here, but I can't because I can't
+                            // easily (and locally) prove that we
+                            // *have* reported an
+                            // error. --nikomatsakis
+                            astconv.ty_infer(None, decl.output.span())
+                        })
                 }
 
                 _ => astconv.ty_infer(None, decl.output.span()),
@@ -645,7 +655,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     fn deduce_future_output_from_obligations(
         &self,
         expr_def_id: DefId,
-    ) -> Ty<'tcx> {
+    ) -> Option<Ty<'tcx>> {
         debug!("deduce_future_output_from_obligations(expr_def_id={:?})", expr_def_id);
 
         let ret_coercion =
@@ -688,8 +698,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 } else {
                     None
                 }
-            })
-            .unwrap();
+            });
 
         debug!("deduce_future_output_from_obligations: output_ty={:?}", output_ty);
         output_ty
diff --git a/src/test/ui/async-await/issues/issue-65159.rs b/src/test/ui/async-await/issues/issue-65159.rs
new file mode 100644
index 00000000000..b5fee061f27
--- /dev/null
+++ b/src/test/ui/async-await/issues/issue-65159.rs
@@ -0,0 +1,10 @@
+// Regression test for #65159. We used to ICE.
+//
+// edition:2018
+
+async fn copy() -> Result<()> //~ ERROR wrong number of type arguments
+{
+    Ok(())
+}
+
+fn main() { }
diff --git a/src/test/ui/async-await/issues/issue-65159.stderr b/src/test/ui/async-await/issues/issue-65159.stderr
new file mode 100644
index 00000000000..56d2c38b302
--- /dev/null
+++ b/src/test/ui/async-await/issues/issue-65159.stderr
@@ -0,0 +1,9 @@
+error[E0107]: wrong number of type arguments: expected 2, found 1
+  --> $DIR/issue-65159.rs:5:20
+   |
+LL | async fn copy() -> Result<()>
+   |                    ^^^^^^^^^^ expected 2 type arguments
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0107`.