@@ -3010,7 +3010,28 @@ impl<'a> LoweringContext<'a> {
3010
3010
)
3011
3011
} ) ,
3012
3012
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
+ } )
3014
3035
}
3015
3036
ExprKind :: Match ( ref expr, ref arms) => hir:: ExprMatch (
3016
3037
P ( self . lower_expr ( expr) ) ,
@@ -3539,12 +3560,8 @@ impl<'a> LoweringContext<'a> {
3539
3560
3540
3561
self . expr_call ( e. span , from, hir_vec ! [ err_expr] )
3541
3562
} ;
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) ;
3548
3565
let thin_attrs = ThinVec :: from ( attrs) ;
3549
3566
let catch_scope = self . catch_scopes . last ( ) . map ( |x| * x) ;
3550
3567
let ret_expr = if let Some ( catch_node) = catch_scope {
@@ -4079,6 +4096,18 @@ impl<'a> LoweringContext<'a> {
4079
4096
)
4080
4097
}
4081
4098
}
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
+ }
4082
4111
}
4083
4112
4084
4113
fn body_ids ( bodies : & BTreeMap < hir:: BodyId , hir:: Body > ) -> Vec < hir:: BodyId > {
0 commit comments