@@ -12,7 +12,7 @@ use rustc_ast::ptr::P as AstP;
12
12
use rustc_ast:: * ;
13
13
use rustc_data_structures:: stack:: ensure_sufficient_stack;
14
14
use rustc_hir as hir;
15
- use rustc_hir:: def:: Res ;
15
+ use rustc_hir:: def:: { DefKind , Res } ;
16
16
use rustc_hir:: definitions:: DefPathData ;
17
17
use rustc_session:: errors:: report_lit_error;
18
18
use rustc_span:: source_map:: { respan, Spanned } ;
@@ -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 (
@@ -350,30 +350,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
350
350
}
351
351
}
352
352
353
- fn lower_binop ( & mut self , b : BinOp ) -> hir:: BinOp {
354
- Spanned {
355
- node : match b. node {
356
- BinOpKind :: Add => hir:: BinOpKind :: Add ,
357
- BinOpKind :: Sub => hir:: BinOpKind :: Sub ,
358
- BinOpKind :: Mul => hir:: BinOpKind :: Mul ,
359
- BinOpKind :: Div => hir:: BinOpKind :: Div ,
360
- BinOpKind :: Rem => hir:: BinOpKind :: Rem ,
361
- BinOpKind :: And => hir:: BinOpKind :: And ,
362
- BinOpKind :: Or => hir:: BinOpKind :: Or ,
363
- BinOpKind :: BitXor => hir:: BinOpKind :: BitXor ,
364
- BinOpKind :: BitAnd => hir:: BinOpKind :: BitAnd ,
365
- BinOpKind :: BitOr => hir:: BinOpKind :: BitOr ,
366
- BinOpKind :: Shl => hir:: BinOpKind :: Shl ,
367
- BinOpKind :: Shr => hir:: BinOpKind :: Shr ,
368
- BinOpKind :: Eq => hir:: BinOpKind :: Eq ,
369
- BinOpKind :: Lt => hir:: BinOpKind :: Lt ,
370
- BinOpKind :: Le => hir:: BinOpKind :: Le ,
371
- BinOpKind :: Ne => hir:: BinOpKind :: Ne ,
372
- BinOpKind :: Ge => hir:: BinOpKind :: Ge ,
373
- BinOpKind :: Gt => hir:: BinOpKind :: Gt ,
374
- } ,
375
- span : self . lower_span ( b. span ) ,
376
- }
353
+ fn lower_binop ( & mut self , b : BinOp ) -> BinOp {
354
+ Spanned { node : b. node , span : self . lower_span ( b. span ) }
377
355
}
378
356
379
357
fn lower_legacy_const_generics (
@@ -395,7 +373,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
395
373
let node_id = self . next_node_id ( ) ;
396
374
397
375
// Add a definition for the in-band const def.
398
- self . create_def ( parent_def_id. def_id , node_id, DefPathData :: AnonConst , f. span ) ;
376
+ self . create_def (
377
+ parent_def_id. def_id ,
378
+ node_id,
379
+ DefPathData :: AnonConst ,
380
+ DefKind :: AnonConst ,
381
+ f. span ,
382
+ ) ;
399
383
400
384
let anon_const = AnonConst { id : node_id, value : arg } ;
401
385
generic_args. push ( AngleBracketedArg :: Arg ( GenericArg :: Const ( anon_const) ) ) ;
@@ -524,15 +508,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
524
508
this. mark_span_with_reason (
525
509
DesugaringKind :: TryBlock ,
526
510
expr. span ,
527
- this. allow_try_trait . clone ( ) ,
511
+ Some ( this. allow_try_trait . clone ( ) ) ,
528
512
) ,
529
513
expr,
530
514
)
531
515
} else {
532
516
let try_span = this. mark_span_with_reason (
533
517
DesugaringKind :: TryBlock ,
534
518
this. tcx . sess . source_map ( ) . end_point ( body. span ) ,
535
- this. allow_try_trait . clone ( ) ,
519
+ Some ( this. allow_try_trait . clone ( ) ) ,
536
520
) ;
537
521
538
522
( try_span, this. expr_unit ( try_span) )
@@ -612,8 +596,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
612
596
let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
613
597
614
598
// Resume argument type: `ResumeTy`
615
- let unstable_span =
616
- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
599
+ let unstable_span = self . mark_span_with_reason (
600
+ DesugaringKind :: Async ,
601
+ span,
602
+ Some ( self . allow_gen_future . clone ( ) ) ,
603
+ ) ;
617
604
let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span) ;
618
605
let input_ty = hir:: Ty {
619
606
hir_id : self . next_id ( ) ,
@@ -735,7 +722,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
735
722
let unstable_span = self . mark_span_with_reason (
736
723
DesugaringKind :: Async ,
737
724
span,
738
- self . allow_gen_future . clone ( ) ,
725
+ Some ( self . allow_gen_future . clone ( ) ) ,
739
726
) ;
740
727
self . lower_attrs (
741
728
inner_hir_id,
@@ -772,17 +759,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
772
759
match self . coroutine_kind {
773
760
Some ( hir:: CoroutineKind :: Async ( _) ) => { }
774
761
Some ( hir:: CoroutineKind :: Coroutine ) | Some ( hir:: CoroutineKind :: Gen ( _) ) | None => {
775
- self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
762
+ return hir :: ExprKind :: Err ( self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
776
763
await_kw_span,
777
764
item_span : self . current_item ,
778
- } ) ;
765
+ } ) ) ;
779
766
}
780
767
}
781
768
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, None ) ;
782
769
let gen_future_span = self . mark_span_with_reason (
783
770
DesugaringKind :: Await ,
784
771
full_span,
785
- self . allow_gen_future . clone ( ) ,
772
+ Some ( self . allow_gen_future . clone ( ) ) ,
786
773
) ;
787
774
let expr = self . lower_expr_mut ( expr) ;
788
775
let expr_hir_id = expr. hir_id ;
@@ -935,9 +922,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
935
922
) -> hir:: ExprKind < ' hir > {
936
923
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
937
924
938
- let ( body_id, coroutine_option) = self . with_new_scopes ( move |this| {
939
- let prev = this. current_item ;
940
- this. current_item = Some ( fn_decl_span) ;
925
+ let ( body_id, coroutine_option) = self . with_new_scopes ( fn_decl_span, move |this| {
941
926
let mut coroutine_kind = None ;
942
927
let body_id = this. lower_fn_body ( decl, |this| {
943
928
let e = this. lower_expr_mut ( body) ;
@@ -946,7 +931,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
946
931
} ) ;
947
932
let coroutine_option =
948
933
this. coroutine_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
949
- this. current_item = prev;
950
934
( body_id, coroutine_option)
951
935
} ) ;
952
936
@@ -1032,7 +1016,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1032
1016
let outer_decl =
1033
1017
FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1034
1018
1035
- let body = self . with_new_scopes ( |this| {
1019
+ let body = self . with_new_scopes ( fn_decl_span , |this| {
1036
1020
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
1037
1021
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
1038
1022
this. tcx . sess . emit_err ( AsyncNonMoveClosureNotSupported { fn_decl_span } ) ;
@@ -1054,7 +1038,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1054
1038
async_ret_ty,
1055
1039
body. span ,
1056
1040
hir:: CoroutineSource :: Closure ,
1057
- |this| this. with_new_scopes ( |this| this. lower_expr_mut ( body) ) ,
1041
+ |this| this. with_new_scopes ( fn_decl_span , |this| this. lower_expr_mut ( body) ) ,
1058
1042
) ;
1059
1043
let hir_id = this. lower_node_id ( inner_closure_id) ;
1060
1044
this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
@@ -1494,7 +1478,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
1494
1478
match self . coroutine_kind {
1495
1479
Some ( hir:: CoroutineKind :: Gen ( _) ) => { }
1496
1480
Some ( hir:: CoroutineKind :: Async ( _) ) => {
1497
- self . tcx . sess . emit_err ( AsyncCoroutinesNotSupported { span } ) ;
1481
+ return hir:: ExprKind :: Err (
1482
+ self . tcx . sess . emit_err ( AsyncCoroutinesNotSupported { span } ) ,
1483
+ ) ;
1498
1484
}
1499
1485
Some ( hir:: CoroutineKind :: Coroutine ) | None => {
1500
1486
if !self . tcx . features ( ) . coroutines {
@@ -1640,13 +1626,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
1640
1626
let unstable_span = self . mark_span_with_reason (
1641
1627
DesugaringKind :: QuestionMark ,
1642
1628
span,
1643
- self . allow_try_trait . clone ( ) ,
1629
+ Some ( self . allow_try_trait . clone ( ) ) ,
1644
1630
) ;
1645
1631
let try_span = self . tcx . sess . source_map ( ) . end_point ( span) ;
1646
1632
let try_span = self . mark_span_with_reason (
1647
1633
DesugaringKind :: QuestionMark ,
1648
1634
try_span,
1649
- self . allow_try_trait . clone ( ) ,
1635
+ Some ( self . allow_try_trait . clone ( ) ) ,
1650
1636
) ;
1651
1637
1652
1638
// `Try::branch(<expr>)`
@@ -1739,7 +1725,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1739
1725
let unstable_span = self . mark_span_with_reason (
1740
1726
DesugaringKind :: YeetExpr ,
1741
1727
span,
1742
- self . allow_try_trait . clone ( ) ,
1728
+ Some ( self . allow_try_trait . clone ( ) ) ,
1743
1729
) ;
1744
1730
1745
1731
let from_yeet_expr = self . wrap_in_try_constructor (
0 commit comments