@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
16
16
use rustc_hir:: definitions:: DefPathData ;
17
17
use rustc_session:: errors:: report_lit_error;
18
18
use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
19
- use rustc_span:: symbol:: { sym, Ident } ;
19
+ use rustc_span:: symbol:: { sym, Ident , Symbol } ;
20
20
use rustc_span:: DUMMY_SP ;
21
21
use thin_vec:: thin_vec;
22
22
@@ -1757,6 +1757,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
1757
1757
self . arena . alloc ( self . expr ( sp, hir:: ExprKind :: Tup ( & [ ] ) ) )
1758
1758
}
1759
1759
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
+
1760
1797
fn expr_call_mut (
1761
1798
& mut self ,
1762
1799
span : Span ,
@@ -1808,6 +1845,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
1808
1845
)
1809
1846
}
1810
1847
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
+
1811
1869
pub ( super ) fn expr_ident (
1812
1870
& mut self ,
1813
1871
sp : Span ,
@@ -1866,6 +1924,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
1866
1924
self . expr ( b. span , hir:: ExprKind :: Block ( b, None ) )
1867
1925
}
1868
1926
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
+
1869
1940
pub ( super ) fn expr ( & mut self , span : Span , kind : hir:: ExprKind < ' hir > ) -> hir:: Expr < ' hir > {
1870
1941
let hir_id = self . next_id ( ) ;
1871
1942
hir:: Expr { hir_id, kind, span : self . lower_span ( span) }
0 commit comments