@@ -72,7 +72,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
72
72
let kind = match & e. kind {
73
73
ExprKind :: Array ( exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
74
74
ExprKind :: ConstBlock ( c) => {
75
- let c = self . with_new_scopes ( |this| hir:: ConstBlock {
75
+ let c = self . with_new_scopes ( c . value . span , |this| hir:: ConstBlock {
76
76
def_id : this. local_def_id ( c. id ) ,
77
77
hir_id : this. lower_node_id ( c. id ) ,
78
78
body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
@@ -189,7 +189,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
189
189
None ,
190
190
e. span ,
191
191
hir:: CoroutineSource :: Block ,
192
- |this| this. with_new_scopes ( |this| this. lower_block_expr ( block) ) ,
192
+ |this| this. with_new_scopes ( e . span , |this| this. lower_block_expr ( block) ) ,
193
193
) ,
194
194
ExprKind :: Await ( expr, await_kw_span) => self . lower_expr_await ( * await_kw_span, expr) ,
195
195
ExprKind :: Closure ( box Closure {
@@ -323,7 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
323
323
None ,
324
324
e. span ,
325
325
hir:: CoroutineSource :: Block ,
326
- |this| this. with_new_scopes ( |this| this. lower_block_expr ( block) ) ,
326
+ |this| this. with_new_scopes ( e . span , |this| this. lower_block_expr ( block) ) ,
327
327
) ,
328
328
ExprKind :: Yield ( opt_expr) => self . lower_expr_yield ( e. span , opt_expr. as_deref ( ) ) ,
329
329
ExprKind :: Err => hir:: ExprKind :: Err (
@@ -781,10 +781,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
781
781
match self . coroutine_kind {
782
782
Some ( hir:: CoroutineKind :: Async ( _) ) => { }
783
783
Some ( hir:: CoroutineKind :: Coroutine ) | Some ( hir:: CoroutineKind :: Gen ( _) ) | None => {
784
- self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
784
+ return hir :: ExprKind :: Err ( self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
785
785
await_kw_span,
786
786
item_span : self . current_item ,
787
- } ) ;
787
+ } ) ) ;
788
788
}
789
789
}
790
790
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, None ) ;
@@ -944,9 +944,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
944
944
) -> hir:: ExprKind < ' hir > {
945
945
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
946
946
947
- let ( body_id, coroutine_option) = self . with_new_scopes ( move |this| {
948
- let prev = this. current_item ;
949
- this. current_item = Some ( fn_decl_span) ;
947
+ let ( body_id, coroutine_option) = self . with_new_scopes ( fn_decl_span, move |this| {
950
948
let mut coroutine_kind = None ;
951
949
let body_id = this. lower_fn_body ( decl, |this| {
952
950
let e = this. lower_expr_mut ( body) ;
@@ -955,7 +953,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
955
953
} ) ;
956
954
let coroutine_option =
957
955
this. coroutine_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
958
- this. current_item = prev;
959
956
( body_id, coroutine_option)
960
957
} ) ;
961
958
@@ -1041,7 +1038,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1041
1038
let outer_decl =
1042
1039
FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1043
1040
1044
- let body = self . with_new_scopes ( |this| {
1041
+ let body = self . with_new_scopes ( fn_decl_span , |this| {
1045
1042
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
1046
1043
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
1047
1044
this. tcx . sess . emit_err ( AsyncNonMoveClosureNotSupported { fn_decl_span } ) ;
@@ -1063,7 +1060,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1063
1060
async_ret_ty,
1064
1061
body. span ,
1065
1062
hir:: CoroutineSource :: Closure ,
1066
- |this| this. with_new_scopes ( |this| this. lower_expr_mut ( body) ) ,
1063
+ |this| this. with_new_scopes ( fn_decl_span , |this| this. lower_expr_mut ( body) ) ,
1067
1064
) ;
1068
1065
let hir_id = this. lower_node_id ( inner_closure_id) ;
1069
1066
this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
@@ -1503,7 +1500,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
1503
1500
match self . coroutine_kind {
1504
1501
Some ( hir:: CoroutineKind :: Gen ( _) ) => { }
1505
1502
Some ( hir:: CoroutineKind :: Async ( _) ) => {
1506
- self . tcx . sess . emit_err ( AsyncCoroutinesNotSupported { span } ) ;
1503
+ return hir:: ExprKind :: Err (
1504
+ self . tcx . sess . emit_err ( AsyncCoroutinesNotSupported { span } ) ,
1505
+ ) ;
1507
1506
}
1508
1507
Some ( hir:: CoroutineKind :: Coroutine ) | None => {
1509
1508
if !self . tcx . features ( ) . coroutines {
0 commit comments