@@ -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 (
@@ -756,10 +756,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
756
756
match self . coroutine_kind {
757
757
Some ( hir:: CoroutineKind :: Async ( _) ) => { }
758
758
Some ( hir:: CoroutineKind :: Coroutine ) | Some ( hir:: CoroutineKind :: Gen ( _) ) | None => {
759
- self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
759
+ return hir :: ExprKind :: Err ( self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
760
760
await_kw_span,
761
761
item_span : self . current_item ,
762
- } ) ;
762
+ } ) ) ;
763
763
}
764
764
}
765
765
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, None ) ;
@@ -919,9 +919,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
919
919
) -> hir:: ExprKind < ' hir > {
920
920
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
921
921
922
- let ( body_id, coroutine_option) = self . with_new_scopes ( move |this| {
923
- let prev = this. current_item ;
924
- this. current_item = Some ( fn_decl_span) ;
922
+ let ( body_id, coroutine_option) = self . with_new_scopes ( fn_decl_span, move |this| {
925
923
let mut coroutine_kind = None ;
926
924
let body_id = this. lower_fn_body ( decl, |this| {
927
925
let e = this. lower_expr_mut ( body) ;
@@ -930,7 +928,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
930
928
} ) ;
931
929
let coroutine_option =
932
930
this. coroutine_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
933
- this. current_item = prev;
934
931
( body_id, coroutine_option)
935
932
} ) ;
936
933
@@ -1016,7 +1013,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1016
1013
let outer_decl =
1017
1014
FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1018
1015
1019
- let body = self . with_new_scopes ( |this| {
1016
+ let body = self . with_new_scopes ( fn_decl_span , |this| {
1020
1017
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
1021
1018
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
1022
1019
this. tcx . sess . emit_err ( AsyncNonMoveClosureNotSupported { fn_decl_span } ) ;
@@ -1038,7 +1035,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1038
1035
async_ret_ty,
1039
1036
body. span ,
1040
1037
hir:: CoroutineSource :: Closure ,
1041
- |this| this. with_new_scopes ( |this| this. lower_expr_mut ( body) ) ,
1038
+ |this| this. with_new_scopes ( fn_decl_span , |this| this. lower_expr_mut ( body) ) ,
1042
1039
) ;
1043
1040
let hir_id = this. lower_node_id ( inner_closure_id) ;
1044
1041
this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
@@ -1478,7 +1475,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
1478
1475
match self . coroutine_kind {
1479
1476
Some ( hir:: CoroutineKind :: Gen ( _) ) => { }
1480
1477
Some ( hir:: CoroutineKind :: Async ( _) ) => {
1481
- self . tcx . sess . emit_err ( AsyncCoroutinesNotSupported { span } ) ;
1478
+ return hir:: ExprKind :: Err (
1479
+ self . tcx . sess . emit_err ( AsyncCoroutinesNotSupported { span } ) ,
1480
+ ) ;
1482
1481
}
1483
1482
Some ( hir:: CoroutineKind :: Coroutine ) | None => {
1484
1483
if !self . tcx . features ( ) . coroutines {
0 commit comments