@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313use rustc_middle:: ty:: TyCtxt ;
1414use rustc_session:: errors:: report_lit_error;
1515use rustc_span:: source_map:: { Spanned , respan} ;
16- use rustc_span:: { DUMMY_SP , DesugaringKind , Ident , Span , Symbol , sym} ;
16+ use rustc_span:: { ByteSymbol , DUMMY_SP , DesugaringKind , Ident , Span , Symbol , sym} ;
1717use thin_vec:: { ThinVec , thin_vec} ;
1818use visit:: { Visitor , walk_expr} ;
1919
@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924 arena_vec ! [ self ; new_unchecked, get_context] ,
925925 ) ,
926926 } ;
927- self . arena . alloc ( self . expr_unsafe ( call) )
927+ self . arena . alloc ( self . expr_unsafe ( span , call) )
928928 } ;
929929
930930 // `::std::task::Poll::Ready(result) => break result`
@@ -1771,8 +1771,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
17711771 let pat = self . lower_pat ( pat) ;
17721772 let for_span =
17731773 self . mark_span_with_reason ( DesugaringKind :: ForLoop , self . lower_span ( e. span ) , None ) ;
1774- let head_span = self . mark_span_with_reason ( DesugaringKind :: ForLoop , head. span , None ) ;
1775- let pat_span = self . mark_span_with_reason ( DesugaringKind :: ForLoop , pat. span , None ) ;
1774+ let for_ctxt = for_span. ctxt ( ) ;
1775+
1776+ // Try to point both the head and pat spans to their position in the for loop
1777+ // rather than inside a macro.
1778+ let head_span =
1779+ head. span . find_ancestor_in_same_ctxt ( e. span ) . unwrap_or ( head. span ) . with_ctxt ( for_ctxt) ;
1780+ let pat_span =
1781+ pat. span . find_ancestor_in_same_ctxt ( e. span ) . unwrap_or ( pat. span ) . with_ctxt ( for_ctxt) ;
17761782
17771783 let loop_hir_id = self . lower_node_id ( e. id ) ;
17781784 let label = self . lower_label ( opt_label, e. id , loop_hir_id) ;
@@ -1826,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18261832 arena_vec ! [ self ; iter] ,
18271833 ) ) ;
18281834 // `unsafe { ... }`
1829- let iter = self . arena . alloc ( self . expr_unsafe ( iter) ) ;
1835+ let iter = self . arena . alloc ( self . expr_unsafe ( head_span , iter) ) ;
18301836 let kind = self . make_lowered_await ( head_span, iter, FutureKind :: AsyncIterator ) ;
18311837 self . arena . alloc ( hir:: Expr { hir_id : self . next_id ( ) , kind, span : head_span } )
18321838 }
@@ -1881,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18811887 arena_vec ! [ self ; iter] ,
18821888 ) ) ;
18831889 // `unsafe { ... }`
1884- let iter = self . arena . alloc ( self . expr_unsafe ( iter) ) ;
1890+ let iter = self . arena . alloc ( self . expr_unsafe ( head_span , iter) ) ;
18851891 let inner_match_expr = self . arena . alloc ( self . expr_match (
18861892 for_span,
18871893 iter,
@@ -1923,7 +1929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19231929 /// ControlFlow::Break(residual) =>
19241930 /// #[allow(unreachable_code)]
19251931 /// // If there is an enclosing `try {...}`:
1926- /// break 'catch_target Try::from_residual (residual),
1932+ /// break 'catch_target Residual::into_try_type (residual),
19271933 /// // Otherwise:
19281934 /// return Try::from_residual(residual),
19291935 /// }
@@ -1973,7 +1979,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
19731979 let ( residual_local, residual_local_nid) = self . pat_ident ( try_span, residual_ident) ;
19741980 let residual_expr = self . expr_ident_mut ( try_span, residual_ident, residual_local_nid) ;
19751981 let from_residual_expr = self . wrap_in_try_constructor (
1976- hir:: LangItem :: TryTraitFromResidual ,
1982+ if self . catch_scope . is_some ( ) {
1983+ hir:: LangItem :: ResidualIntoTryType
1984+ } else {
1985+ hir:: LangItem :: TryTraitFromResidual
1986+ } ,
19771987 try_span,
19781988 self . arena . alloc ( residual_expr) ,
19791989 unstable_span,
@@ -2097,30 +2107,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
20972107 self . arena . alloc ( self . expr ( sp, hir:: ExprKind :: Tup ( & [ ] ) ) )
20982108 }
20992109
2100- fn expr_uint ( & mut self , sp : Span , ty : ast :: UintTy , value : u128 ) -> hir:: Expr < ' hir > {
2110+ pub ( super ) fn expr_str ( & mut self , sp : Span , value : Symbol ) -> hir:: Expr < ' hir > {
21012111 let lit = hir:: Lit {
21022112 span : self . lower_span ( sp) ,
2103- node : ast:: LitKind :: Int ( value. into ( ) , ast:: LitIntType :: Unsigned ( ty ) ) ,
2113+ node : ast:: LitKind :: Str ( value, ast:: StrStyle :: Cooked ) ,
21042114 } ;
21052115 self . expr ( sp, hir:: ExprKind :: Lit ( lit) )
21062116 }
21072117
2108- pub ( super ) fn expr_usize ( & mut self , sp : Span , value : usize ) -> hir:: Expr < ' hir > {
2109- self . expr_uint ( sp, ast:: UintTy :: Usize , value as u128 )
2110- }
2111-
2112- pub ( super ) fn expr_u32 ( & mut self , sp : Span , value : u32 ) -> hir:: Expr < ' hir > {
2113- self . expr_uint ( sp, ast:: UintTy :: U32 , value as u128 )
2114- }
2115-
2116- pub ( super ) fn expr_u16 ( & mut self , sp : Span , value : u16 ) -> hir:: Expr < ' hir > {
2117- self . expr_uint ( sp, ast:: UintTy :: U16 , value as u128 )
2118- }
2119-
2120- pub ( super ) fn expr_str ( & mut self , sp : Span , value : Symbol ) -> hir:: Expr < ' hir > {
2118+ pub ( super ) fn expr_byte_str ( & mut self , sp : Span , value : ByteSymbol ) -> hir:: Expr < ' hir > {
21212119 let lit = hir:: Lit {
21222120 span : self . lower_span ( sp) ,
2123- node : ast:: LitKind :: Str ( value, ast:: StrStyle :: Cooked ) ,
2121+ node : ast:: LitKind :: ByteStr ( value, ast:: StrStyle :: Cooked ) ,
21242122 } ;
21252123 self . expr ( sp, hir:: ExprKind :: Lit ( lit) )
21262124 }
@@ -2256,9 +2254,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22562254 self . expr ( span, expr_path)
22572255 }
22582256
2259- fn expr_unsafe ( & mut self , expr : & ' hir hir:: Expr < ' hir > ) -> hir:: Expr < ' hir > {
2257+ pub ( super ) fn expr_unsafe (
2258+ & mut self ,
2259+ span : Span ,
2260+ expr : & ' hir hir:: Expr < ' hir > ,
2261+ ) -> hir:: Expr < ' hir > {
22602262 let hir_id = self . next_id ( ) ;
2261- let span = expr. span ;
22622263 self . expr (
22632264 span,
22642265 hir:: ExprKind :: Block (
@@ -2296,15 +2297,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
22962297 self . arena . alloc ( self . expr_block ( b) )
22972298 }
22982299
2299- pub ( super ) fn expr_array_ref (
2300- & mut self ,
2301- span : Span ,
2302- elements : & ' hir [ hir:: Expr < ' hir > ] ,
2303- ) -> hir:: Expr < ' hir > {
2304- let array = self . arena . alloc ( self . expr ( span, hir:: ExprKind :: Array ( elements) ) ) ;
2305- self . expr_ref ( span, array)
2306- }
2307-
23082300 pub ( super ) fn expr_ref ( & mut self , span : Span , expr : & ' hir hir:: Expr < ' hir > ) -> hir:: Expr < ' hir > {
23092301 self . expr ( span, hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Ref , hir:: Mutability :: Not , expr) )
23102302 }
0 commit comments