Skip to content

Commit 02e2a57

Browse files
authored
Rollup merge of rust-lang#63509 - estebank:async-span, r=Centril
Point at the right enclosing scope when using `await` in non-async fn Fix rust-lang#63398.
2 parents d2d49d2 + 25d507f commit 02e2a57

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/librustc/hir/lowering/expr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ impl LoweringContext<'_> {
677677
let fn_decl = self.lower_fn_decl(decl, None, false, None);
678678

679679
self.with_new_scopes(|this| {
680+
let prev = this.current_item;
680681
this.current_item = Some(fn_decl_span);
681682
let mut generator_kind = None;
682683
let body_id = this.lower_fn_body(decl, |this| {
@@ -690,8 +691,10 @@ impl LoweringContext<'_> {
690691
generator_kind,
691692
movability,
692693
);
694+
let capture_clause = this.lower_capture_clause(capture_clause);
695+
this.current_item = prev;
693696
hir::ExprKind::Closure(
694-
this.lower_capture_clause(capture_clause),
697+
capture_clause,
695698
fn_decl,
696699
body_id,
697700
fn_decl_span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2018
2+
#![feature(async_await)]
3+
4+
async fn do_the_thing() -> u8 {
5+
8
6+
}
7+
// #63398: point at the enclosing scope and not the previously seen closure
8+
fn main() { //~ NOTE this is not `async`
9+
let x = move || {};
10+
let y = do_the_thing().await; //~ ERROR `await` is only allowed inside `async` functions
11+
//~^ NOTE only allowed inside `async` functions and blocks
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0728]: `await` is only allowed inside `async` functions and blocks
2+
--> $DIR/non-async-enclosing-span.rs:10:13
3+
|
4+
LL | fn main() {
5+
| ---- this is not `async`
6+
LL | let x = move || {};
7+
LL | let y = do_the_thing().await;
8+
| ^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)