@@ -3,6 +3,7 @@ use crate::base::ExtCtxt;
3
3
use rustc_ast:: attr;
4
4
use rustc_ast:: ptr:: P ;
5
5
use rustc_ast:: { self as ast, AttrVec , BlockCheckMode , Expr , LocalKind , PatKind , UnOp } ;
6
+ use rustc_data_structures:: sync:: Lrc ;
6
7
use rustc_span:: source_map:: Spanned ;
7
8
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
8
9
@@ -330,23 +331,38 @@ impl<'a> ExtCtxt<'a> {
330
331
self . expr_struct ( span, self . path_ident ( span, id) , fields)
331
332
}
332
333
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 > {
334
335
let lit = ast:: Lit :: from_lit_kind ( lit_kind, span) ;
335
336
self . expr ( span, ast:: ExprKind :: Lit ( lit) )
336
337
}
338
+
337
339
pub fn expr_usize ( & self , span : Span , i : usize ) -> P < ast:: Expr > {
338
340
self . expr_lit (
339
341
span,
340
342
ast:: LitKind :: Int ( i as u128 , ast:: LitIntType :: Unsigned ( ast:: UintTy :: Usize ) ) ,
341
343
)
342
344
}
345
+
343
346
pub fn expr_u32 ( & self , sp : Span , u : u32 ) -> P < ast:: Expr > {
344
347
self . expr_lit ( sp, ast:: LitKind :: Int ( u as u128 , ast:: LitIntType :: Unsigned ( ast:: UintTy :: U32 ) ) )
345
348
}
349
+
346
350
pub fn expr_bool ( & self , sp : Span , value : bool ) -> P < ast:: Expr > {
347
351
self . expr_lit ( sp, ast:: LitKind :: Bool ( value) )
348
352
}
349
353
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
+
350
366
/// `[expr1, expr2, ...]`
351
367
pub fn expr_array ( & self , sp : Span , exprs : Vec < P < ast:: Expr > > ) -> P < ast:: Expr > {
352
368
self . expr ( sp, ast:: ExprKind :: Array ( exprs) )
@@ -357,10 +373,6 @@ impl<'a> ExtCtxt<'a> {
357
373
self . expr_addr_of ( sp, self . expr_array ( sp, exprs) )
358
374
}
359
375
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
-
364
376
pub fn expr_cast ( & self , sp : Span , expr : P < ast:: Expr > , ty : P < ast:: Ty > ) -> P < ast:: Expr > {
365
377
self . expr ( sp, ast:: ExprKind :: Cast ( expr, ty) )
366
378
}
0 commit comments