Skip to content

Commit

Permalink
Point at the right enclosing scope when using await in non-async fn
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Aug 13, 2019
1 parent 60960a2 commit 13fd466
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librustc/hir/lowering/expr.rs
Expand Up @@ -677,6 +677,7 @@ impl LoweringContext<'_> {
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| {
Expand All @@ -690,8 +691,10 @@ impl LoweringContext<'_> {
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,
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-63398.rs
@@ -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
}
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-63398.stderr
@@ -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

0 comments on commit 13fd466

Please sign in to comment.