@@ -562,8 +562,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
562
562
)
563
563
}
564
564
565
- /// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok (<expr>) }`,
566
- /// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_ok (()) }`
565
+ /// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_output (<expr>) }`,
566
+ /// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_output (()) }`
567
567
/// and save the block id to use it as a break target for desugaring of the `?` operator.
568
568
fn lower_expr_try_block ( & mut self , body : & Block ) -> hir:: ExprKind < ' hir > {
569
569
self . with_catch_scope ( body. id , |this| {
@@ -592,9 +592,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
592
592
let ok_wrapped_span =
593
593
this. mark_span_with_reason ( DesugaringKind :: TryBlock , tail_expr. span , None ) ;
594
594
595
- // `::std::ops::Try::from_ok ($tail_expr)`
595
+ // `::std::ops::Try::from_output ($tail_expr)`
596
596
block. expr = Some ( this. wrap_in_try_constructor (
597
- hir:: LangItem :: TryFromOk ,
597
+ hir:: LangItem :: TryTraitFromOutput ,
598
598
try_span,
599
599
tail_expr,
600
600
ok_wrapped_span,
@@ -1896,14 +1896,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
1896
1896
self . allow_try_trait . clone ( ) ,
1897
1897
) ;
1898
1898
1899
- // `Try::into_result (<expr>)`
1899
+ // `Try::branch (<expr>)`
1900
1900
let scrutinee = {
1901
1901
// expand <expr>
1902
1902
let sub_expr = self . lower_expr_mut ( sub_expr) ;
1903
1903
1904
1904
self . expr_call_lang_item_fn (
1905
1905
unstable_span,
1906
- hir:: LangItem :: TryIntoResult ,
1906
+ hir:: LangItem :: TryTraitBranch ,
1907
1907
arena_vec ! [ self ; sub_expr] ,
1908
1908
)
1909
1909
} ;
@@ -1921,8 +1921,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1921
1921
} ;
1922
1922
let attrs = vec ! [ attr] ;
1923
1923
1924
- // `Ok (val) => #[allow(unreachable_code)] val,`
1925
- let ok_arm = {
1924
+ // `ControlFlow::Continue (val) => #[allow(unreachable_code)] val,`
1925
+ let continue_arm = {
1926
1926
let val_ident = Ident :: with_dummy_span ( sym:: val) ;
1927
1927
let ( val_pat, val_pat_nid) = self . pat_ident ( span, val_ident) ;
1928
1928
let val_expr = self . arena . alloc ( self . expr_ident_with_attrs (
@@ -1931,27 +1931,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
1931
1931
val_pat_nid,
1932
1932
ThinVec :: from ( attrs. clone ( ) ) ,
1933
1933
) ) ;
1934
- let ok_pat = self . pat_ok ( span , val_pat) ;
1935
- self . arm ( ok_pat , val_expr)
1934
+ let continue_pat = self . pat_cf_continue ( unstable_span , val_pat) ;
1935
+ self . arm ( continue_pat , val_expr)
1936
1936
} ;
1937
1937
1938
- // `Err(err) => #[allow(unreachable_code)]
1939
- // return Try::from_error(From::from(err)),`
1940
- let err_arm = {
1941
- let err_ident = Ident :: with_dummy_span ( sym:: err) ;
1942
- let ( err_local, err_local_nid) = self . pat_ident ( try_span, err_ident) ;
1943
- let from_expr = {
1944
- let err_expr = self . expr_ident_mut ( try_span, err_ident, err_local_nid) ;
1945
- self . expr_call_lang_item_fn (
1946
- try_span,
1947
- hir:: LangItem :: FromFrom ,
1948
- arena_vec ! [ self ; err_expr] ,
1949
- )
1950
- } ;
1951
- let from_err_expr = self . wrap_in_try_constructor (
1952
- hir:: LangItem :: TryFromError ,
1953
- unstable_span,
1954
- from_expr,
1938
+ // `ControlFlow::Break(residual) =>
1939
+ // #[allow(unreachable_code)]
1940
+ // return Try::from_residual(residual),`
1941
+ let break_arm = {
1942
+ let residual_ident = Ident :: with_dummy_span ( sym:: residual) ;
1943
+ let ( residual_local, residual_local_nid) = self . pat_ident ( try_span, residual_ident) ;
1944
+ let residual_expr = self . expr_ident_mut ( try_span, residual_ident, residual_local_nid) ;
1945
+ let from_residual_expr = self . wrap_in_try_constructor (
1946
+ hir:: LangItem :: TryTraitFromResidual ,
1947
+ try_span,
1948
+ self . arena . alloc ( residual_expr) ,
1955
1949
unstable_span,
1956
1950
) ;
1957
1951
let thin_attrs = ThinVec :: from ( attrs) ;
@@ -1962,25 +1956,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
1962
1956
try_span,
1963
1957
hir:: ExprKind :: Break (
1964
1958
hir:: Destination { label : None , target_id } ,
1965
- Some ( from_err_expr ) ,
1959
+ Some ( from_residual_expr ) ,
1966
1960
) ,
1967
1961
thin_attrs,
1968
1962
) )
1969
1963
} else {
1970
1964
self . arena . alloc ( self . expr (
1971
1965
try_span,
1972
- hir:: ExprKind :: Ret ( Some ( from_err_expr ) ) ,
1966
+ hir:: ExprKind :: Ret ( Some ( from_residual_expr ) ) ,
1973
1967
thin_attrs,
1974
1968
) )
1975
1969
} ;
1976
1970
1977
- let err_pat = self . pat_err ( try_span, err_local ) ;
1978
- self . arm ( err_pat , ret_expr)
1971
+ let break_pat = self . pat_cf_break ( try_span, residual_local ) ;
1972
+ self . arm ( break_pat , ret_expr)
1979
1973
} ;
1980
1974
1981
1975
hir:: ExprKind :: Match (
1982
1976
scrutinee,
1983
- arena_vec ! [ self ; err_arm , ok_arm ] ,
1977
+ arena_vec ! [ self ; break_arm , continue_arm ] ,
1984
1978
hir:: MatchSource :: TryDesugar ,
1985
1979
)
1986
1980
}
0 commit comments