@@ -3010,7 +3010,28 @@ impl<'a> LoweringContext<'a> {
30103010 )
30113011 } ) ,
30123012 ExprKind :: Catch ( ref body) => {
3013- self . with_catch_scope ( body. id , |this| hir:: ExprBlock ( this. lower_block ( body, true ) ) )
3013+ self . with_catch_scope ( body. id , |this| {
3014+ let unstable_span =
3015+ this. allow_internal_unstable ( CompilerDesugaringKind :: Catch , body. span ) ;
3016+ let mut block = this. lower_block ( body, true ) . into_inner ( ) ;
3017+ let tail = block. expr . take ( ) . map_or_else (
3018+ || {
3019+ let LoweredNodeId { node_id, hir_id } = this. next_id ( ) ;
3020+ let span = this. sess . codemap ( ) . end_point ( unstable_span) ;
3021+ hir:: Expr {
3022+ id : node_id,
3023+ span,
3024+ node : hir:: ExprTup ( hir_vec ! [ ] ) ,
3025+ attrs : ThinVec :: new ( ) ,
3026+ hir_id,
3027+ }
3028+ } ,
3029+ |x : P < hir:: Expr > | x. into_inner ( ) ,
3030+ ) ;
3031+ block. expr = Some ( this. wrap_in_try_constructor (
3032+ "from_ok" , tail, unstable_span) ) ;
3033+ hir:: ExprBlock ( P ( block) )
3034+ } )
30143035 }
30153036 ExprKind :: Match ( ref expr, ref arms) => hir:: ExprMatch (
30163037 P ( self . lower_expr ( expr) ) ,
@@ -3539,12 +3560,8 @@ impl<'a> LoweringContext<'a> {
35393560
35403561 self . expr_call ( e. span , from, hir_vec ! [ err_expr] )
35413562 } ;
3542- let from_err_expr = {
3543- let path = & [ "ops" , "Try" , "from_error" ] ;
3544- let from_err = P ( self . expr_std_path ( unstable_span, path, ThinVec :: new ( ) ) ) ;
3545- P ( self . expr_call ( e. span , from_err, hir_vec ! [ from_expr] ) )
3546- } ;
3547-
3563+ let from_err_expr =
3564+ self . wrap_in_try_constructor ( "from_error" , from_expr, unstable_span) ;
35483565 let thin_attrs = ThinVec :: from ( attrs) ;
35493566 let catch_scope = self . catch_scopes . last ( ) . map ( |x| * x) ;
35503567 let ret_expr = if let Some ( catch_node) = catch_scope {
@@ -4079,6 +4096,18 @@ impl<'a> LoweringContext<'a> {
40794096 )
40804097 }
40814098 }
4099+
4100+ fn wrap_in_try_constructor (
4101+ & mut self ,
4102+ method : & ' static str ,
4103+ e : hir:: Expr ,
4104+ unstable_span : Span ,
4105+ ) -> P < hir:: Expr > {
4106+ let path = & [ "ops" , "Try" , method] ;
4107+ let from_err = P ( self . expr_std_path ( unstable_span, path,
4108+ ThinVec :: new ( ) ) ) ;
4109+ P ( self . expr_call ( e. span , from_err, hir_vec ! [ e] ) )
4110+ }
40824111}
40834112
40844113fn body_ids ( bodies : & BTreeMap < hir:: BodyId , hir:: Body > ) -> Vec < hir:: BodyId > {
0 commit comments