@@ -16,7 +16,7 @@ use rustc_session::diagnostics::report_lit_error;
1616use rustc_span:: {
1717 ByteSymbol , DUMMY_SP , DesugaringKind , Ident , Span , Spanned , Symbol , respan, span_bug, sym,
1818} ;
19- use thin_vec:: { ThinVec , thin_vec } ;
19+ use thin_vec:: ThinVec ;
2020mod closure;
2121
2222use crate :: diagnostics:: {
@@ -1933,13 +1933,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
19331933 /// Desugar `ExprKind::Try` from: `<expr>?` into:
19341934 /// ```ignore (pseudo-rust)
19351935 /// match Try::branch(<expr>) {
1936- /// ControlFlow::Continue(val) => #[allow(unreachable_code)] val, ,
1936+ /// ControlFlow::Continue(val) => val,
19371937 /// ControlFlow::Break(residual) =>
1938- /// #[allow(unreachable_code)]
1939- /// // If there is an enclosing `try {...}`:
1940- /// break 'catch_target Residual::into_try_type(residual),
1938+ /// // If there is an enclosing homogeneous `try {...}`:
1939+ /// break 'catch_target residual_into_try_type(residual),
1940+ /// // If there is an enclosing heterogeneous`try {...}`:
1941+ /// break 'catch_target FromResidual::from_residual(residual),
19411942 /// // Otherwise:
1942- /// return Try ::from_residual(residual),
1943+ /// return FromResidual ::from_residual(residual),
19431944 /// }
19441945 /// ```
19451946 fn lower_expr_try ( & mut self , span : Span , sub_expr : & Expr ) -> hir:: ExprKind < ' hir > {
@@ -1967,21 +1968,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
19671968 )
19681969 } ;
19691970
1970- let attrs: AttrVec = thin_vec ! [ self . unreachable_code_attr( try_span) ] ;
1971-
1972- // `ControlFlow::Continue(val) => #[allow(unreachable_code)] val,`
1971+ // `ControlFlow::Continue(val) => val,`
19731972 let continue_arm = {
19741973 let val_ident = Ident :: with_dummy_span ( sym:: val) ;
19751974 let ( val_pat, val_pat_nid) = self . pat_ident ( span, val_ident) ;
19761975 let val_expr = self . expr_ident ( span, val_ident, val_pat_nid) ;
1977- self . lower_attrs ( val_expr. hir_id , & attrs, span, Target :: Expression ) ;
19781976 let continue_pat = self . pat_cf_continue ( unstable_span, val_pat) ;
19791977 self . arm ( continue_pat, val_expr, try_span)
19801978 } ;
19811979
1982- // `ControlFlow::Break(residual) =>
1983- // #[allow(unreachable_code)]
1984- // return Try::from_residual(residual),`
1980+ // `ControlFlow::Break(residual) => <return or break> <constructor>(residual),`
19851981 let break_arm = {
19861982 let residual_ident = Ident :: with_dummy_span ( sym:: residual) ;
19871983 let ( residual_local, residual_local_nid) = self . pat_ident ( try_span, residual_ident) ;
@@ -2016,7 +2012,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
20162012 let ret_expr = self . checked_return ( Some ( from_residual_expr) ) ;
20172013 self . arena . alloc ( self . expr ( try_span, ret_expr) )
20182014 } ;
2019- self . lower_attrs ( ret_expr. hir_id , & attrs, span, Target :: Expression ) ;
20202015
20212016 let break_pat = self . pat_cf_break ( try_span, residual_local) ;
20222017 self . arm ( break_pat, ret_expr, try_span)
@@ -2357,18 +2352,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23572352 body : expr,
23582353 }
23592354 }
2360-
2361- /// `#[allow(unreachable_code)]`
2362- pub ( super ) fn unreachable_code_attr ( & mut self , span : Span ) -> Attribute {
2363- let attr = attr:: mk_attr_nested_word (
2364- & self . tcx . sess . psess . attr_id_generator ,
2365- AttrStyle :: Outer ,
2366- sym:: allow,
2367- sym:: unreachable_code,
2368- span,
2369- ) ;
2370- attr
2371- }
23722355}
23732356
23742357/// Used by [`LoweringContext::make_lowered_await`] to customize the desugaring based on what kind
0 commit comments