@@ -560,8 +560,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
560
560
)
561
561
}
562
562
563
- /// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok (<expr>) }`,
564
- /// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_ok (()) }`
563
+ /// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_output (<expr>) }`,
564
+ /// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_output (()) }`
565
565
/// and save the block id to use it as a break target for desugaring of the `?` operator.
566
566
fn lower_expr_try_block ( & mut self , body : & Block ) -> hir:: ExprKind < ' hir > {
567
567
self . with_catch_scope ( body. id , |this| {
@@ -590,9 +590,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
590
590
let ok_wrapped_span =
591
591
this. mark_span_with_reason ( DesugaringKind :: TryBlock , tail_expr. span , None ) ;
592
592
593
- // `::std::ops::Try::from_ok ($tail_expr)`
593
+ // `::std::ops::Try::from_output ($tail_expr)`
594
594
block. expr = Some ( this. wrap_in_try_constructor (
595
- hir:: LangItem :: TryFromOk ,
595
+ hir:: LangItem :: TryTraitFromOutput ,
596
596
try_span,
597
597
tail_expr,
598
598
ok_wrapped_span,
@@ -1579,14 +1579,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
1579
1579
self . allow_try_trait . clone ( ) ,
1580
1580
) ;
1581
1581
1582
- // `Try::into_result (<expr>)`
1582
+ // `Try::branch (<expr>)`
1583
1583
let scrutinee = {
1584
1584
// expand <expr>
1585
1585
let sub_expr = self . lower_expr_mut ( sub_expr) ;
1586
1586
1587
1587
self . expr_call_lang_item_fn (
1588
1588
unstable_span,
1589
- hir:: LangItem :: TryIntoResult ,
1589
+ hir:: LangItem :: TryTraitBranch ,
1590
1590
arena_vec ! [ self ; sub_expr] ,
1591
1591
)
1592
1592
} ;
@@ -1604,8 +1604,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1604
1604
} ;
1605
1605
let attrs = vec ! [ attr] ;
1606
1606
1607
- // `Ok (val) => #[allow(unreachable_code)] val,`
1608
- let ok_arm = {
1607
+ // `ControlFlow::Continue (val) => #[allow(unreachable_code)] val,`
1608
+ let continue_arm = {
1609
1609
let val_ident = Ident :: with_dummy_span ( sym:: val) ;
1610
1610
let ( val_pat, val_pat_nid) = self . pat_ident ( span, val_ident) ;
1611
1611
let val_expr = self . arena . alloc ( self . expr_ident_with_attrs (
@@ -1614,27 +1614,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
1614
1614
val_pat_nid,
1615
1615
ThinVec :: from ( attrs. clone ( ) ) ,
1616
1616
) ) ;
1617
- let ok_pat = self . pat_ok ( span , val_pat) ;
1618
- self . arm ( ok_pat , val_expr)
1617
+ let continue_pat = self . pat_cf_continue ( unstable_span , val_pat) ;
1618
+ self . arm ( continue_pat , val_expr)
1619
1619
} ;
1620
1620
1621
- // `Err(err) => #[allow(unreachable_code)]
1622
- // return Try::from_error(From::from(err)),`
1623
- let err_arm = {
1624
- let err_ident = Ident :: with_dummy_span ( sym:: err) ;
1625
- let ( err_local, err_local_nid) = self . pat_ident ( try_span, err_ident) ;
1626
- let from_expr = {
1627
- let err_expr = self . expr_ident_mut ( try_span, err_ident, err_local_nid) ;
1628
- self . expr_call_lang_item_fn (
1629
- try_span,
1630
- hir:: LangItem :: FromFrom ,
1631
- arena_vec ! [ self ; err_expr] ,
1632
- )
1633
- } ;
1634
- let from_err_expr = self . wrap_in_try_constructor (
1635
- hir:: LangItem :: TryFromError ,
1636
- unstable_span,
1637
- from_expr,
1621
+ // `ControlFlow::Break(residual) =>
1622
+ // #[allow(unreachable_code)]
1623
+ // return Try::from_residual(residual),`
1624
+ let break_arm = {
1625
+ let residual_ident = Ident :: with_dummy_span ( sym:: residual) ;
1626
+ let ( residual_local, residual_local_nid) = self . pat_ident ( try_span, residual_ident) ;
1627
+ let residual_expr = self . expr_ident_mut ( try_span, residual_ident, residual_local_nid) ;
1628
+ let from_residual_expr = self . wrap_in_try_constructor (
1629
+ hir:: LangItem :: TryTraitFromResidual ,
1630
+ try_span,
1631
+ self . arena . alloc ( residual_expr) ,
1638
1632
unstable_span,
1639
1633
) ;
1640
1634
let thin_attrs = ThinVec :: from ( attrs) ;
@@ -1645,25 +1639,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
1645
1639
try_span,
1646
1640
hir:: ExprKind :: Break (
1647
1641
hir:: Destination { label : None , target_id } ,
1648
- Some ( from_err_expr ) ,
1642
+ Some ( from_residual_expr ) ,
1649
1643
) ,
1650
1644
thin_attrs,
1651
1645
) )
1652
1646
} else {
1653
1647
self . arena . alloc ( self . expr (
1654
1648
try_span,
1655
- hir:: ExprKind :: Ret ( Some ( from_err_expr ) ) ,
1649
+ hir:: ExprKind :: Ret ( Some ( from_residual_expr ) ) ,
1656
1650
thin_attrs,
1657
1651
) )
1658
1652
} ;
1659
1653
1660
- let err_pat = self . pat_err ( try_span, err_local ) ;
1661
- self . arm ( err_pat , ret_expr)
1654
+ let break_pat = self . pat_cf_break ( try_span, residual_local ) ;
1655
+ self . arm ( break_pat , ret_expr)
1662
1656
} ;
1663
1657
1664
1658
hir:: ExprKind :: Match (
1665
1659
scrutinee,
1666
- arena_vec ! [ self ; err_arm , ok_arm ] ,
1660
+ arena_vec ! [ self ; break_arm , continue_arm ] ,
1667
1661
hir:: MatchSource :: TryDesugar ,
1668
1662
)
1669
1663
}
0 commit comments