]> git.lizzy.rs Git - rust.git/commitdiff
Point at the right enclosing scope when using `await` in non-async fn
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 13 Aug 2019 06:56:13 +0000 (23:56 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 13 Aug 2019 07:52:07 +0000 (00:52 -0700)
src/librustc/hir/lowering/expr.rs
src/test/ui/issues/issue-63398.rs [new file with mode: 0644]
src/test/ui/issues/issue-63398.stderr [new file with mode: 0644]

index d273006fbe07eddb21cfea12a94e7e80bd365995..e3a5400942d1a625363e06698b7654f77d340c1c 100644 (file)
@@ -677,6 +677,7 @@ fn lower_expr_closure(
         let fn_decl = self.lower_fn_decl(decl, None, false, None);
 
         self.with_new_scopes(|this| {
+            let prev = this.current_item;
             this.current_item = Some(fn_decl_span);
             let mut generator_kind = None;
             let body_id = this.lower_fn_body(decl, |this| {
@@ -690,8 +691,10 @@ fn lower_expr_closure(
                 generator_kind,
                 movability,
             );
+            let capture_clause = this.lower_capture_clause(capture_clause);
+            this.current_item = prev;
             hir::ExprKind::Closure(
-                this.lower_capture_clause(capture_clause),
+                capture_clause,
                 fn_decl,
                 body_id,
                 fn_decl_span,
diff --git a/src/test/ui/issues/issue-63398.rs b/src/test/ui/issues/issue-63398.rs
new file mode 100644 (file)
index 0000000..a031687
--- /dev/null
@@ -0,0 +1,11 @@
+// edition:2018
+#![feature(async_await)]
+
+async fn do_the_thing() -> u8 {
+    8
+}
+
+fn main() {
+    let x = move || {};
+    let y = do_the_thing().await; //~ ERROR `await` is only allowed inside `async` functions
+}
diff --git a/src/test/ui/issues/issue-63398.stderr b/src/test/ui/issues/issue-63398.stderr
new file mode 100644 (file)
index 0000000..b2ba46c
--- /dev/null
@@ -0,0 +1,11 @@
+error[E0728]: `await` is only allowed inside `async` functions and blocks
+  --> $DIR/issue-63398.rs:10:13
+   |
+LL | fn main() {
+   |    ---- this is not `async`
+LL |     let x = move || {};
+LL |     let y = do_the_thing().await;
+   |             ^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
+
+error: aborting due to previous error
+