@@ -12,7 +12,7 @@ use rustc_ast::ptr::P as AstP;
1212use rustc_ast:: * ;
1313use rustc_data_structures:: stack:: ensure_sufficient_stack;
1414use rustc_hir as hir;
15- use rustc_hir:: def:: Res ;
15+ use rustc_hir:: def:: { DefKind , Res } ;
1616use rustc_hir:: definitions:: DefPathData ;
1717use rustc_session:: errors:: report_lit_error;
1818use rustc_span:: source_map:: { respan, Spanned } ;
@@ -72,7 +72,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
7272 let kind = match & e. kind {
7373 ExprKind :: Array ( exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
7474 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 {
7676 def_id : this. local_def_id ( c. id ) ,
7777 hir_id : this. lower_node_id ( c. id ) ,
7878 body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
@@ -189,7 +189,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
189189 None ,
190190 e. span ,
191191 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) ) ,
193193 ) ,
194194 ExprKind :: Await ( expr, await_kw_span) => self . lower_expr_await ( * await_kw_span, expr) ,
195195 ExprKind :: Closure ( box Closure {
@@ -323,7 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323 None ,
324324 e. span ,
325325 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) ) ,
327327 ) ,
328328 ExprKind :: Yield ( opt_expr) => self . lower_expr_yield ( e. span , opt_expr. as_deref ( ) ) ,
329329 ExprKind :: Err => hir:: ExprKind :: Err (
@@ -350,30 +350,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
350350 }
351351 }
352352
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 ) }
377355 }
378356
379357 fn lower_legacy_const_generics (
@@ -395,7 +373,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
395373 let node_id = self . next_node_id ( ) ;
396374
397375 // 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+ ) ;
399383
400384 let anon_const = AnonConst { id : node_id, value : arg } ;
401385 generic_args. push ( AngleBracketedArg :: Arg ( GenericArg :: Const ( anon_const) ) ) ;
@@ -524,15 +508,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
524508 this. mark_span_with_reason (
525509 DesugaringKind :: TryBlock ,
526510 expr. span ,
527- this. allow_try_trait . clone ( ) ,
511+ Some ( this. allow_try_trait . clone ( ) ) ,
528512 ) ,
529513 expr,
530514 )
531515 } else {
532516 let try_span = this. mark_span_with_reason (
533517 DesugaringKind :: TryBlock ,
534518 this. tcx . sess . source_map ( ) . end_point ( body. span ) ,
535- this. allow_try_trait . clone ( ) ,
519+ Some ( this. allow_try_trait . clone ( ) ) ,
536520 ) ;
537521
538522 ( try_span, this. expr_unit ( try_span) )
@@ -612,8 +596,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
612596 let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
613597
614598 // 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+ ) ;
617604 let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span) ;
618605 let input_ty = hir:: Ty {
619606 hir_id : self . next_id ( ) ,
@@ -735,7 +722,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
735722 let unstable_span = self . mark_span_with_reason (
736723 DesugaringKind :: Async ,
737724 span,
738- self . allow_gen_future . clone ( ) ,
725+ Some ( self . allow_gen_future . clone ( ) ) ,
739726 ) ;
740727 self . lower_attrs (
741728 inner_hir_id,
@@ -772,17 +759,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
772759 match self . coroutine_kind {
773760 Some ( hir:: CoroutineKind :: Async ( _) ) => { }
774761 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 {
776763 await_kw_span,
777764 item_span : self . current_item ,
778- } ) ;
765+ } ) ) ;
779766 }
780767 }
781768 let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, None ) ;
782769 let gen_future_span = self . mark_span_with_reason (
783770 DesugaringKind :: Await ,
784771 full_span,
785- self . allow_gen_future . clone ( ) ,
772+ Some ( self . allow_gen_future . clone ( ) ) ,
786773 ) ;
787774 let expr = self . lower_expr_mut ( expr) ;
788775 let expr_hir_id = expr. hir_id ;
@@ -935,9 +922,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
935922 ) -> hir:: ExprKind < ' hir > {
936923 let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
937924
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| {
941926 let mut coroutine_kind = None ;
942927 let body_id = this. lower_fn_body ( decl, |this| {
943928 let e = this. lower_expr_mut ( body) ;
@@ -946,7 +931,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
946931 } ) ;
947932 let coroutine_option =
948933 this. coroutine_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
949- this. current_item = prev;
950934 ( body_id, coroutine_option)
951935 } ) ;
952936
@@ -1032,7 +1016,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10321016 let outer_decl =
10331017 FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
10341018
1035- let body = self . with_new_scopes ( |this| {
1019+ let body = self . with_new_scopes ( fn_decl_span , |this| {
10361020 // FIXME(cramertj): allow `async` non-`move` closures with arguments.
10371021 if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
10381022 this. tcx . sess . emit_err ( AsyncNonMoveClosureNotSupported { fn_decl_span } ) ;
@@ -1054,7 +1038,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10541038 async_ret_ty,
10551039 body. span ,
10561040 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) ) ,
10581042 ) ;
10591043 let hir_id = this. lower_node_id ( inner_closure_id) ;
10601044 this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
@@ -1494,7 +1478,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
14941478 match self . coroutine_kind {
14951479 Some ( hir:: CoroutineKind :: Gen ( _) ) => { }
14961480 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+ ) ;
14981484 }
14991485 Some ( hir:: CoroutineKind :: Coroutine ) | None => {
15001486 if !self . tcx . features ( ) . coroutines {
@@ -1640,13 +1626,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
16401626 let unstable_span = self . mark_span_with_reason (
16411627 DesugaringKind :: QuestionMark ,
16421628 span,
1643- self . allow_try_trait . clone ( ) ,
1629+ Some ( self . allow_try_trait . clone ( ) ) ,
16441630 ) ;
16451631 let try_span = self . tcx . sess . source_map ( ) . end_point ( span) ;
16461632 let try_span = self . mark_span_with_reason (
16471633 DesugaringKind :: QuestionMark ,
16481634 try_span,
1649- self . allow_try_trait . clone ( ) ,
1635+ Some ( self . allow_try_trait . clone ( ) ) ,
16501636 ) ;
16511637
16521638 // `Try::branch(<expr>)`
@@ -1739,7 +1725,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17391725 let unstable_span = self . mark_span_with_reason (
17401726 DesugaringKind :: YeetExpr ,
17411727 span,
1742- self . allow_try_trait . clone ( ) ,
1728+ Some ( self . allow_try_trait . clone ( ) ) ,
17431729 ) ;
17441730
17451731 let from_yeet_expr = self . wrap_in_try_constructor (
0 commit comments