@@ -3,6 +3,7 @@ use crate::base::ExtCtxt;
33use rustc_ast:: attr;
44use rustc_ast:: ptr:: P ;
55use rustc_ast:: { self as ast, AttrVec , BlockCheckMode , Expr , LocalKind , PatKind , UnOp } ;
6+ use rustc_data_structures:: sync:: Lrc ;
67use rustc_span:: source_map:: Spanned ;
78use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
89
@@ -330,23 +331,38 @@ impl<'a> ExtCtxt<'a> {
330331 self . expr_struct ( span, self . path_ident ( span, id) , fields)
331332 }
332333
333- pub fn expr_lit ( & self , span : Span , lit_kind : ast:: LitKind ) -> P < ast:: Expr > {
334+ fn expr_lit ( & self , span : Span , lit_kind : ast:: LitKind ) -> P < ast:: Expr > {
334335 let lit = ast:: Lit :: from_lit_kind ( lit_kind, span) ;
335336 self . expr ( span, ast:: ExprKind :: Lit ( lit) )
336337 }
338+
337339 pub fn expr_usize ( & self , span : Span , i : usize ) -> P < ast:: Expr > {
338340 self . expr_lit (
339341 span,
340342 ast:: LitKind :: Int ( i as u128 , ast:: LitIntType :: Unsigned ( ast:: UintTy :: Usize ) ) ,
341343 )
342344 }
345+
343346 pub fn expr_u32 ( & self , sp : Span , u : u32 ) -> P < ast:: Expr > {
344347 self . expr_lit ( sp, ast:: LitKind :: Int ( u as u128 , ast:: LitIntType :: Unsigned ( ast:: UintTy :: U32 ) ) )
345348 }
349+
346350 pub fn expr_bool ( & self , sp : Span , value : bool ) -> P < ast:: Expr > {
347351 self . expr_lit ( sp, ast:: LitKind :: Bool ( value) )
348352 }
349353
354+ pub fn expr_str ( & self , sp : Span , s : Symbol ) -> P < ast:: Expr > {
355+ self . expr_lit ( sp, ast:: LitKind :: Str ( s, ast:: StrStyle :: Cooked ) )
356+ }
357+
358+ pub fn expr_char ( & self , sp : Span , ch : char ) -> P < ast:: Expr > {
359+ self . expr_lit ( sp, ast:: LitKind :: Char ( ch) )
360+ }
361+
362+ pub fn expr_byte_str ( & self , sp : Span , bytes : Vec < u8 > ) -> P < ast:: Expr > {
363+ self . expr_lit ( sp, ast:: LitKind :: ByteStr ( Lrc :: from ( bytes) ) )
364+ }
365+
350366 /// `[expr1, expr2, ...]`
351367 pub fn expr_array ( & self , sp : Span , exprs : Vec < P < ast:: Expr > > ) -> P < ast:: Expr > {
352368 self . expr ( sp, ast:: ExprKind :: Array ( exprs) )
@@ -357,10 +373,6 @@ impl<'a> ExtCtxt<'a> {
357373 self . expr_addr_of ( sp, self . expr_array ( sp, exprs) )
358374 }
359375
360- pub fn expr_str ( & self , sp : Span , s : Symbol ) -> P < ast:: Expr > {
361- self . expr_lit ( sp, ast:: LitKind :: Str ( s, ast:: StrStyle :: Cooked ) )
362- }
363-
364376 pub fn expr_cast ( & self , sp : Span , expr : P < ast:: Expr > , ty : P < ast:: Ty > ) -> P < ast:: Expr > {
365377 self . expr ( sp, ast:: ExprKind :: Cast ( expr, ty) )
366378 }
0 commit comments