@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
1616use rustc_hir:: definitions:: DefPathData ;
1717use rustc_session:: errors:: report_lit_error;
1818use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
19- use rustc_span:: symbol:: { sym, Ident } ;
19+ use rustc_span:: symbol:: { sym, Ident , Symbol } ;
2020use rustc_span:: DUMMY_SP ;
2121use thin_vec:: thin_vec;
2222
@@ -1757,6 +1757,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
17571757 self . arena . alloc ( self . expr ( sp, hir:: ExprKind :: Tup ( & [ ] ) ) )
17581758 }
17591759
1760+ pub ( super ) fn expr_usize ( & mut self , sp : Span , value : usize ) -> hir:: Expr < ' hir > {
1761+ self . expr (
1762+ sp,
1763+ hir:: ExprKind :: Lit ( hir:: Lit {
1764+ span : sp,
1765+ node : ast:: LitKind :: Int (
1766+ value as u128 ,
1767+ ast:: LitIntType :: Unsigned ( ast:: UintTy :: Usize ) ,
1768+ ) ,
1769+ } ) ,
1770+ )
1771+ }
1772+
1773+ pub ( super ) fn expr_u32 ( & mut self , sp : Span , value : u32 ) -> hir:: Expr < ' hir > {
1774+ self . expr (
1775+ sp,
1776+ hir:: ExprKind :: Lit ( hir:: Lit {
1777+ span : sp,
1778+ node : ast:: LitKind :: Int ( value. into ( ) , ast:: LitIntType :: Unsigned ( ast:: UintTy :: U32 ) ) ,
1779+ } ) ,
1780+ )
1781+ }
1782+
1783+ pub ( super ) fn expr_char ( & mut self , sp : Span , value : char ) -> hir:: Expr < ' hir > {
1784+ self . expr ( sp, hir:: ExprKind :: Lit ( hir:: Lit { span : sp, node : ast:: LitKind :: Char ( value) } ) )
1785+ }
1786+
1787+ pub ( super ) fn expr_str ( & mut self , sp : Span , value : Symbol ) -> hir:: Expr < ' hir > {
1788+ self . expr (
1789+ sp,
1790+ hir:: ExprKind :: Lit ( hir:: Lit {
1791+ span : sp,
1792+ node : ast:: LitKind :: Str ( value, ast:: StrStyle :: Cooked ) ,
1793+ } ) ,
1794+ )
1795+ }
1796+
17601797 fn expr_call_mut (
17611798 & mut self ,
17621799 span : Span ,
@@ -1808,6 +1845,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
18081845 )
18091846 }
18101847
1848+ /// `<LangItem>::name`
1849+ pub ( super ) fn expr_lang_item_type_relative (
1850+ & mut self ,
1851+ span : Span ,
1852+ lang_item : hir:: LangItem ,
1853+ name : Symbol ,
1854+ ) -> hir:: Expr < ' hir > {
1855+ let path = hir:: ExprKind :: Path ( hir:: QPath :: TypeRelative (
1856+ self . arena . alloc ( self . ty (
1857+ span,
1858+ hir:: TyKind :: Path ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) , None ) ) ,
1859+ ) ) ,
1860+ self . arena . alloc ( hir:: PathSegment :: new (
1861+ Ident :: new ( name, span) ,
1862+ self . next_id ( ) ,
1863+ Res :: Err ,
1864+ ) ) ,
1865+ ) ) ;
1866+ self . expr ( span, path)
1867+ }
1868+
18111869 pub ( super ) fn expr_ident (
18121870 & mut self ,
18131871 sp : Span ,
@@ -1866,6 +1924,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
18661924 self . expr ( b. span , hir:: ExprKind :: Block ( b, None ) )
18671925 }
18681926
1927+ pub ( super ) fn expr_array_ref (
1928+ & mut self ,
1929+ span : Span ,
1930+ elements : & ' hir [ hir:: Expr < ' hir > ] ,
1931+ ) -> hir:: Expr < ' hir > {
1932+ let addrof = hir:: ExprKind :: AddrOf (
1933+ hir:: BorrowKind :: Ref ,
1934+ hir:: Mutability :: Not ,
1935+ self . arena . alloc ( self . expr ( span, hir:: ExprKind :: Array ( elements) ) ) ,
1936+ ) ;
1937+ self . expr ( span, addrof)
1938+ }
1939+
18691940 pub ( super ) fn expr ( & mut self , span : Span , kind : hir:: ExprKind < ' hir > ) -> hir:: Expr < ' hir > {
18701941 let hir_id = self . next_id ( ) ;
18711942 hir:: Expr { hir_id, kind, span : self . lower_span ( span) }
0 commit comments