summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_expand/src/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_expand/src/build.rs')
-rw-r--r--compiler/rustc_expand/src/build.rs50
1 files changed, 25 insertions, 25 deletions
diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs
index 4812bdd9d..9b16e79d4 100644
--- a/compiler/rustc_expand/src/build.rs
+++ b/compiler/rustc_expand/src/build.rs
@@ -1,8 +1,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_ast::{attr, token, util::literal};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span;
@@ -88,14 +87,14 @@ impl<'a> ExtCtxt<'a> {
self.anon_const(span, ast::ExprKind::Path(None, self.path_ident(span, ident)))
}
- pub fn ty_rptr(
+ pub fn ty_ref(
&self,
span: Span,
ty: P<ast::Ty>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::Mutability,
) -> P<ast::Ty> {
- self.ty(span, ast::TyKind::Rptr(lifetime, self.ty_mt(ty, mutbl)))
+ self.ty(span, ast::TyKind::Ref(lifetime, self.ty_mt(ty, mutbl)))
}
pub fn ty_ptr(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> {
@@ -332,36 +331,36 @@ impl<'a> ExtCtxt<'a> {
self.expr_struct(span, self.path_ident(span, id), fields)
}
- fn expr_lit(&self, span: Span, lit_kind: ast::LitKind) -> P<ast::Expr> {
- let token_lit = lit_kind.to_token_lit();
- self.expr(span, ast::ExprKind::Lit(token_lit))
+ pub fn expr_usize(&self, span: Span, n: usize) -> P<ast::Expr> {
+ let suffix = Some(ast::UintTy::Usize.name());
+ let lit = token::Lit::new(token::Integer, sym::integer(n), suffix);
+ 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_u32(&self, span: Span, n: u32) -> P<ast::Expr> {
+ let suffix = Some(ast::UintTy::U32.name());
+ let lit = token::Lit::new(token::Integer, sym::integer(n), suffix);
+ self.expr(span, ast::ExprKind::Lit(lit))
}
- pub fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
- self.expr_lit(sp, ast::LitKind::Bool(value))
+ pub fn expr_bool(&self, span: Span, value: bool) -> P<ast::Expr> {
+ let lit = token::Lit::new(token::Bool, if value { kw::True } else { kw::False }, None);
+ self.expr(span, ast::ExprKind::Lit(lit))
}
- 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_str(&self, span: Span, s: Symbol) -> P<ast::Expr> {
+ let lit = token::Lit::new(token::Str, literal::escape_string_symbol(s), None);
+ self.expr(span, ast::ExprKind::Lit(lit))
}
- pub fn expr_char(&self, sp: Span, ch: char) -> P<ast::Expr> {
- self.expr_lit(sp, ast::LitKind::Char(ch))
+ pub fn expr_char(&self, span: Span, ch: char) -> P<ast::Expr> {
+ let lit = token::Lit::new(token::Char, literal::escape_char_symbol(ch), None);
+ self.expr(span, ast::ExprKind::Lit(lit))
}
- pub fn expr_byte_str(&self, sp: Span, bytes: Vec<u8>) -> P<ast::Expr> {
- self.expr_lit(sp, ast::LitKind::ByteStr(Lrc::from(bytes)))
+ pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<ast::Expr> {
+ let lit = token::Lit::new(token::ByteStr, literal::escape_byte_str_symbol(&bytes), None);
+ self.expr(span, ast::ExprKind::Lit(lit))
}
/// `[expr1, expr2, ...]`
@@ -534,6 +533,7 @@ impl<'a> ExtCtxt<'a> {
ast::ExprKind::Closure(Box::new(ast::Closure {
binder: ast::ClosureBinder::NotPresent,
capture_clause: ast::CaptureBy::Ref,
+ constness: ast::Const::No,
asyncness: ast::Async::No,
movability: ast::Movability::Movable,
fn_decl,
@@ -627,7 +627,7 @@ impl<'a> ExtCtxt<'a> {
// Builds `#[name = val]`.
//
- // Note: `span` is used for both the identifer and the value.
+ // Note: `span` is used for both the identifier and the value.
pub fn attr_name_value_str(&self, name: Symbol, val: Symbol, span: Span) -> ast::Attribute {
let g = &self.sess.parse_sess.attr_id_generator;
attr::mk_attr_name_value_str(g, ast::AttrStyle::Outer, name, val, span)