Make ExtCtxt::expr_lit
non-pub
.
By using `expr_str` more and adding `expr_{char,byte_str}`.
This commit is contained in:
parent
7d1e5a485c
commit
d7a041f607
5 changed files with 23 additions and 18 deletions
|
@ -3,6 +3,7 @@ use crate::base::ExtCtxt;
|
|||
use rustc_ast::attr;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
|
||||
|
@ -330,23 +331,38 @@ impl<'a> ExtCtxt<'a> {
|
|||
self.expr_struct(span, self.path_ident(span, id), fields)
|
||||
}
|
||||
|
||||
pub fn expr_lit(&self, span: Span, lit_kind: ast::LitKind) -> P<ast::Expr> {
|
||||
fn expr_lit(&self, span: Span, lit_kind: ast::LitKind) -> P<ast::Expr> {
|
||||
let lit = ast::Lit::from_lit_kind(lit_kind, span);
|
||||
self.expr(span, ast::ExprKind::Lit(lit))
|
||||
}
|
||||
|
||||
pub fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
|
||||
self.expr_lit(
|
||||
span,
|
||||
ast::LitKind::Int(i as u128, ast::LitIntType::Unsigned(ast::UintTy::Usize)),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
|
||||
self.expr_lit(sp, ast::LitKind::Int(u as u128, ast::LitIntType::Unsigned(ast::UintTy::U32)))
|
||||
}
|
||||
|
||||
pub fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
|
||||
self.expr_lit(sp, ast::LitKind::Bool(value))
|
||||
}
|
||||
|
||||
pub fn expr_str(&self, sp: Span, s: Symbol) -> P<ast::Expr> {
|
||||
self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked))
|
||||
}
|
||||
|
||||
pub fn expr_char(&self, sp: Span, ch: char) -> P<ast::Expr> {
|
||||
self.expr_lit(sp, ast::LitKind::Char(ch))
|
||||
}
|
||||
|
||||
pub fn expr_byte_str(&self, sp: Span, bytes: Vec<u8>) -> P<ast::Expr> {
|
||||
self.expr_lit(sp, ast::LitKind::ByteStr(Lrc::from(bytes)))
|
||||
}
|
||||
|
||||
/// `[expr1, expr2, ...]`
|
||||
pub fn expr_array(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
|
||||
self.expr(sp, ast::ExprKind::Array(exprs))
|
||||
|
@ -357,10 +373,6 @@ impl<'a> ExtCtxt<'a> {
|
|||
self.expr_addr_of(sp, self.expr_array(sp, exprs))
|
||||
}
|
||||
|
||||
pub fn expr_str(&self, sp: Span, s: Symbol) -> P<ast::Expr> {
|
||||
self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked))
|
||||
}
|
||||
|
||||
pub fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> {
|
||||
self.expr(sp, ast::ExprKind::Cast(expr, ty))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue