[breaking-change] don't pub export ast::Lit_ variants

This commit is contained in:
Oliver Schneider 2016-02-08 17:06:20 +01:00
parent 05d4cefd63
commit 69072c4f5d
26 changed files with 142 additions and 142 deletions

View File

@ -421,7 +421,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
fn const_val_to_expr(value: &ConstVal) -> P<hir::Expr> {
let node = match value {
&ConstVal::Bool(b) => ast::LitBool(b),
&ConstVal::Bool(b) => ast::LitKind::Bool(b),
_ => unreachable!()
};
P(hir::Expr {

View File

@ -1322,22 +1322,22 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {
fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option<Ty>) -> ConstVal {
match lit.node {
ast::LitStr(ref s, _) => Str((*s).clone()),
ast::LitByteStr(ref data) => {
ast::LitKind::Str(ref s, _) => Str((*s).clone()),
ast::LitKind::ByteStr(ref data) => {
ByteStr(data.clone())
}
ast::LitByte(n) => Uint(n as u64),
ast::LitChar(n) => Uint(n as u64),
ast::LitInt(n, ast::SignedIntLit(_)) => Int(n as i64),
ast::LitInt(n, ast::UnsuffixedIntLit) => {
ast::LitKind::Byte(n) => Uint(n as u64),
ast::LitKind::Char(n) => Uint(n as u64),
ast::LitKind::Int(n, ast::SignedIntLit(_)) => Int(n as i64),
ast::LitKind::Int(n, ast::UnsuffixedIntLit) => {
match ty_hint.map(|ty| &ty.sty) {
Some(&ty::TyUint(_)) => Uint(n),
_ => Int(n as i64)
}
}
ast::LitInt(n, ast::UnsignedIntLit(_)) => Uint(n),
ast::LitFloat(ref n, _) |
ast::LitFloatUnsuffixed(ref n) => {
ast::LitKind::Int(n, ast::UnsignedIntLit(_)) => Uint(n),
ast::LitKind::Float(ref n, _) |
ast::LitKind::FloatUnsuffixed(ref n) => {
if let Ok(x) = n.parse::<f64>() {
Float(x)
} else {
@ -1345,7 +1345,7 @@ fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option<Ty>)
sess.span_bug(span, "could not evaluate float literal (see issue #31407)");
}
}
ast::LitBool(b) => Bool(b)
ast::LitKind::Bool(b) => Bool(b)
}
}

View File

@ -232,7 +232,7 @@ mod svh_visitor {
SawExprTup,
SawExprBinary(hir::BinOp_),
SawExprUnary(hir::UnOp),
SawExprLit(ast::Lit_),
SawExprLit(ast::LitKind),
SawExprCast,
SawExprType,
SawExprIf,

View File

@ -563,7 +563,7 @@ impl RustcDefaultCalls {
ast::MetaWord(ref word) => println!("{}", word),
ast::MetaNameValue(ref name, ref value) => {
println!("{}=\"{}\"", name, match value.node {
ast::LitStr(ref s, _) => s,
ast::LitKind::Str(ref s, _) => s,
_ => continue,
});
}

View File

@ -73,7 +73,7 @@ impl LateLintPass for WhileTrue {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
if let hir::ExprWhile(ref cond, _, _) = e.node {
if let hir::ExprLit(ref lit) = cond.node {
if let ast::LitBool(true) = lit.node {
if let ast::LitKind::Bool(true) = lit.node {
cx.span_lint(WHILE_TRUE, e.span,
"denote infinite loops with loop { ... }");
}

View File

@ -103,10 +103,10 @@ impl LateLintPass for TypeLimits {
hir::ExprUnary(hir::UnNeg, ref expr) => {
if let hir::ExprLit(ref lit) = expr.node {
match lit.node {
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
ast::LitKind::Int(_, ast::UnsignedIntLit(_)) => {
forbid_unsigned_negation(cx, e.span);
},
ast::LitInt(_, ast::UnsuffixedIntLit) => {
ast::LitKind::Int(_, ast::UnsuffixedIntLit) => {
if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty {
forbid_unsigned_negation(cx, e.span);
}
@ -139,7 +139,7 @@ impl LateLintPass for TypeLimits {
if let Some(bits) = opt_ty_bits {
let exceeding = if let hir::ExprLit(ref lit) = r.node {
if let ast::LitInt(shift, _) = lit.node { shift >= bits }
if let ast::LitKind::Int(shift, _) = lit.node { shift >= bits }
else { false }
} else {
match eval_const_expr_partial(cx.tcx, &r, ExprTypeChecked, None) {
@ -159,8 +159,8 @@ impl LateLintPass for TypeLimits {
match cx.tcx.node_id_to_type(e.id).sty {
ty::TyInt(t) => {
match lit.node {
ast::LitInt(v, ast::SignedIntLit(_)) |
ast::LitInt(v, ast::UnsuffixedIntLit) => {
ast::LitKind::Int(v, ast::SignedIntLit(_)) |
ast::LitKind::Int(v, ast::UnsuffixedIntLit) => {
let int_type = if let ast::IntTy::Is = t {
cx.sess().target.int_type
} else {
@ -189,8 +189,9 @@ impl LateLintPass for TypeLimits {
};
let (min, max) = uint_ty_range(uint_type);
let lit_val: u64 = match lit.node {
ast::LitByte(_v) => return, // _v is u8, within range by definition
ast::LitInt(v, _) => v,
// _v is u8, within range by definition
ast::LitKind::Byte(_v) => return,
ast::LitKind::Int(v, _) => v,
_ => panic!()
};
if lit_val < min || lit_val > max {
@ -201,8 +202,8 @@ impl LateLintPass for TypeLimits {
ty::TyFloat(t) => {
let (min, max) = float_ty_range(t);
let lit_val: f64 = match lit.node {
ast::LitFloat(ref v, _) |
ast::LitFloatUnsuffixed(ref v) => {
ast::LitKind::Float(ref v, _) |
ast::LitKind::FloatUnsuffixed(ref v) => {
match v.parse() {
Ok(f) => f,
Err(_) => return
@ -311,8 +312,8 @@ impl LateLintPass for TypeLimits {
let (min, max) = int_ty_range(int_ty);
let lit_val: i64 = match lit.node {
hir::ExprLit(ref li) => match li.node {
ast::LitInt(v, ast::SignedIntLit(_)) |
ast::LitInt(v, ast::UnsuffixedIntLit) => v as i64,
ast::LitKind::Int(v, ast::SignedIntLit(_)) |
ast::LitKind::Int(v, ast::UnsuffixedIntLit) => v as i64,
_ => return true
},
_ => panic!()
@ -323,7 +324,7 @@ impl LateLintPass for TypeLimits {
let (min, max): (u64, u64) = uint_ty_range(uint_ty);
let lit_val: u64 = match lit.node {
hir::ExprLit(ref li) => match li.node {
ast::LitInt(v, _) => v,
ast::LitKind::Int(v, _) => v,
_ => return true
},
_ => panic!()

View File

@ -1548,7 +1548,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
}
ast::MetaNameValue(ref name, ref value) => {
match value.node {
ast::LitStr(ref value, _) => {
ast::LitKind::Str(ref value, _) => {
rbml_w.start_tag(tag_meta_item_name_value);
rbml_w.wr_tagged_str(tag_meta_item_name, name);
rbml_w.wr_tagged_str(tag_meta_item_value, value);

View File

@ -52,7 +52,7 @@ use rustc_front::hir;
use std::ffi::{CStr, CString};
use std::borrow::Cow;
use libc::c_uint;
use syntax::ast;
use syntax::ast::{self, LitKind};
use syntax::attr;
use syntax::parse::token;
use syntax::ptr::P;
@ -64,15 +64,15 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
let _icx = push_ctxt("trans_lit");
debug!("const_lit: {:?}", lit);
match lit.node {
ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false),
ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false),
ast::LitInt(i, ast::SignedIntLit(t)) => {
LitKind::Byte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false),
LitKind::Char(i) => C_integral(Type::char(cx), i as u64, false),
LitKind::Int(i, ast::SignedIntLit(t)) => {
C_integral(Type::int_from_ty(cx, t), i, true)
}
ast::LitInt(u, ast::UnsignedIntLit(t)) => {
LitKind::Int(u, ast::UnsignedIntLit(t)) => {
C_integral(Type::uint_from_ty(cx, t), u, false)
}
ast::LitInt(i, ast::UnsuffixedIntLit) => {
LitKind::Int(i, ast::UnsuffixedIntLit) => {
let lit_int_ty = cx.tcx().node_id_to_type(e.id);
match lit_int_ty.sty {
ty::TyInt(t) => {
@ -87,10 +87,10 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
lit_int_ty))
}
}
ast::LitFloat(ref fs, t) => {
LitKind::Float(ref fs, t) => {
C_floating(&fs, Type::float_from_ty(cx, t))
}
ast::LitFloatUnsuffixed(ref fs) => {
LitKind::FloatUnsuffixed(ref fs) => {
let lit_float_ty = cx.tcx().node_id_to_type(e.id);
match lit_float_ty.sty {
ty::TyFloat(t) => {
@ -102,9 +102,9 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
}
}
}
ast::LitBool(b) => C_bool(cx, b),
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
ast::LitByteStr(ref data) => {
LitKind::Bool(b) => C_bool(cx, b),
LitKind::Str(ref s, _) => C_str_slice(cx, (*s).clone()),
LitKind::ByteStr(ref data) => {
addr_of(cx, C_bytes(cx, &data[..]), 1, "byte_str")
}
}

View File

@ -1153,7 +1153,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
hir::ExprLit(ref lit) => {
match lit.node {
ast::LitStr(ref s, _) => {
ast::LitKind::Str(ref s, _) => {
tvec::trans_lit_str(bcx, expr, (*s).clone(), dest)
}
_ => {

View File

@ -92,7 +92,7 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Handle the "..." case (returns a slice since strings are always unsized):
if let hir::ExprLit(ref lit) = content_expr.node {
if let ast::LitStr(ref s, _) = lit.node {
if let ast::LitKind::Str(ref s, _) = lit.node {
let scratch = rvalue_scratch_datum(bcx, vec_ty, "");
bcx = trans_lit_str(bcx,
content_expr,
@ -180,7 +180,7 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
match content_expr.node {
hir::ExprLit(ref lit) => {
match lit.node {
ast::LitStr(ref s, _) => {
ast::LitKind::Str(ref s, _) => {
match dest {
Ignore => return bcx,
SaveIn(lldest) => {
@ -276,7 +276,7 @@ fn elements_required(bcx: Block, content_expr: &hir::Expr) -> usize {
match content_expr.node {
hir::ExprLit(ref lit) => {
match lit.node {
ast::LitStr(ref s, _) => s.len(),
ast::LitKind::Str(ref s, _) => s.len(),
_ => {
bcx.tcx().sess.span_bug(content_expr.span,
"unexpected evec content")

View File

@ -57,7 +57,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// They can denote both statically and dynamically sized byte arrays
let mut pat_ty = expr_ty;
if let hir::ExprLit(ref lt) = lt.node {
if let ast::LitByteStr(_) = lt.node {
if let ast::LitKind::ByteStr(_) = lt.node {
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
if let ty::TyRef(_, mt) = expected_ty.sty {
if let ty::TySlice(_) = mt.ty.sty {

View File

@ -2606,16 +2606,16 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let tcx = fcx.ccx.tcx;
match lit.node {
ast::LitStr(..) => tcx.mk_static_str(),
ast::LitByteStr(ref v) => {
ast::LitKind::Str(..) => tcx.mk_static_str(),
ast::LitKind::ByteStr(ref v) => {
tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic),
tcx.mk_array(tcx.types.u8, v.len()))
}
ast::LitByte(_) => tcx.types.u8,
ast::LitChar(_) => tcx.types.char,
ast::LitInt(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t),
ast::LitInt(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t),
ast::LitInt(_, ast::UnsuffixedIntLit) => {
ast::LitKind::Byte(_) => tcx.types.u8,
ast::LitKind::Char(_) => tcx.types.char,
ast::LitKind::Int(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t),
ast::LitKind::Int(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t),
ast::LitKind::Int(_, ast::UnsuffixedIntLit) => {
let opt_ty = expected.to_option(fcx).and_then(|ty| {
match ty.sty {
ty::TyInt(_) | ty::TyUint(_) => Some(ty),
@ -2628,8 +2628,8 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
opt_ty.unwrap_or_else(
|| tcx.mk_int_var(fcx.infcx().next_int_var_id()))
}
ast::LitFloat(_, t) => tcx.mk_mach_float(t),
ast::LitFloatUnsuffixed(_) => {
ast::LitKind::Float(_, t) => tcx.mk_mach_float(t),
ast::LitKind::FloatUnsuffixed(_) => {
let opt_ty = expected.to_option(fcx).and_then(|ty| {
match ty.sty {
ty::TyFloat(_) => Some(ty),
@ -2639,7 +2639,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
opt_ty.unwrap_or_else(
|| tcx.mk_float_var(fcx.infcx().next_float_var_id()))
}
ast::LitBool(_) => tcx.types.bool
ast::LitKind::Bool(_) => tcx.types.bool
}
}

View File

@ -2531,9 +2531,9 @@ impl ToSource for syntax::codemap::Span {
fn lit_to_string(lit: &ast::Lit) -> String {
match lit.node {
ast::LitStr(ref st, _) => st.to_string(),
ast::LitByteStr(ref data) => format!("{:?}", data),
ast::LitByte(b) => {
ast::LitKind::Str(ref st, _) => st.to_string(),
ast::LitKind::ByteStr(ref data) => format!("{:?}", data),
ast::LitKind::Byte(b) => {
let mut res = String::from("b'");
for c in (b as char).escape_default() {
res.push(c);
@ -2541,11 +2541,11 @@ fn lit_to_string(lit: &ast::Lit) -> String {
res.push('\'');
res
},
ast::LitChar(c) => format!("'{}'", c),
ast::LitInt(i, _t) => i.to_string(),
ast::LitFloat(ref f, _t) => f.to_string(),
ast::LitFloatUnsuffixed(ref f) => f.to_string(),
ast::LitBool(b) => b.to_string(),
ast::LitKind::Char(c) => format!("'{}'", c),
ast::LitKind::Int(i, _t) => i.to_string(),
ast::LitKind::Float(ref f, _t) => f.to_string(),
ast::LitKind::FloatUnsuffixed(ref f) => f.to_string(),
ast::LitKind::Bool(b) => b.to_string(),
}
}

View File

@ -13,7 +13,6 @@
pub use self::ForeignItem_::*;
pub use self::Item_::*;
pub use self::KleeneOp::*;
pub use self::Lit_::*;
pub use self::LitIntType::*;
pub use self::MacStmtStyle::*;
pub use self::MetaItem_::*;
@ -1264,7 +1263,7 @@ pub enum StrStyle {
}
/// A literal
pub type Lit = Spanned<Lit_>;
pub type Lit = Spanned<LitKind>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum LitIntType {
@ -1274,30 +1273,30 @@ pub enum LitIntType {
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Lit_ {
pub enum LitKind {
/// A string literal (`"foo"`)
LitStr(InternedString, StrStyle),
Str(InternedString, StrStyle),
/// A byte string (`b"foo"`)
LitByteStr(Rc<Vec<u8>>),
ByteStr(Rc<Vec<u8>>),
/// A byte char (`b'f'`)
LitByte(u8),
Byte(u8),
/// A character literal (`'a'`)
LitChar(char),
Char(char),
/// An integer literal (`1u8`)
LitInt(u64, LitIntType),
Int(u64, LitIntType),
/// A float literal (`1f64` or `1E10f64`)
LitFloat(InternedString, FloatTy),
Float(InternedString, FloatTy),
/// A float literal without a suffix (`1.0 or 1.0E10`)
LitFloatUnsuffixed(InternedString),
FloatUnsuffixed(InternedString),
/// A boolean literal
LitBool(bool),
Bool(bool),
}
impl Lit_ {
impl LitKind {
/// Returns true if this literal is a string and false otherwise.
pub fn is_str(&self) -> bool {
match *self {
LitStr(..) => true,
LitKind::Str(..) => true,
_ => false,
}
}

View File

@ -106,7 +106,7 @@ impl AttrMetaMethods for MetaItem {
match self.node {
MetaNameValue(_, ref v) => {
match v.node {
ast::LitStr(ref s, _) => Some((*s).clone()),
ast::LitKind::Str(ref s, _) => Some((*s).clone()),
_ => None,
}
},
@ -173,7 +173,7 @@ impl AttributeMethods for Attribute {
pub fn mk_name_value_item_str(name: InternedString, value: InternedString)
-> P<MetaItem> {
let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr));
let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::CookedStr));
mk_name_value_item(name, value_lit)
}
@ -225,7 +225,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos,
hi: BytePos)
-> Attribute {
let style = doc_comment_style(&text);
let lit = spanned(lo, hi, ast::LitStr(text, ast::CookedStr));
let lit = spanned(lo, hi, ast::LitKind::Str(text, ast::CookedStr));
let attr = Attribute_ {
id: id,
style: style,

View File

@ -349,7 +349,7 @@ impl DummyResult {
pub fn raw_expr(sp: Span) -> P<ast::Expr> {
P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitBool(false)))),
node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitKind::Bool(false)))),
span: sp,
attrs: None,
})
@ -774,7 +774,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str)
let expr = cx.expander().fold_expr(expr);
match expr.node {
ast::ExprKind::Lit(ref l) => match l.node {
ast::LitStr(ref s, style) => return Some(((*s).clone(), style)),
ast::LitKind::Str(ref s, style) => return Some(((*s).clone(), style)),
_ => cx.span_err(l.span, err_msg)
},
_ => cx.span_err(expr.span, err_msg)

View File

@ -139,7 +139,7 @@ pub trait AstBuilder {
fn expr_struct_ident(&self, span: Span, id: ast::Ident,
fields: Vec<ast::Field>) -> P<ast::Expr>;
fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr>;
fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr>;
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>;
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr>;
@ -285,7 +285,7 @@ pub trait AstBuilder {
fn meta_name_value(&self,
sp: Span,
name: InternedString,
value: ast::Lit_)
value: ast::LitKind)
-> P<ast::MetaItem>;
fn item_use(&self, sp: Span,
@ -676,29 +676,30 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_struct(span, self.path_ident(span, id), fields)
}
fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr> {
fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr> {
self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit))))
}
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us)))
self.expr_lit(span, ast::LitKind::Int(i as u64, ast::UnsignedIntLit(ast::UintTy::Us)))
}
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> {
if i < 0 {
let i = (-i) as u64;
let lit = self.expr_lit(sp, ast::LitInt(i, ast::SignedIntLit(ast::IntTy::Is)));
let lit_ty = ast::LitIntType::Signed(ast::IntTy::Is);
let lit = self.expr_lit(sp, ast::LitKind::Int(i, lit_ty));
self.expr_unary(sp, ast::UnOp::Neg, lit)
} else {
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is)))
self.expr_lit(sp, ast::LitKind::Int(i as u64, ast::SignedIntLit(ast::IntTy::Is)))
}
}
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32)))
self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::UnsignedIntLit(ast::UintTy::U32)))
}
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U8)))
self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::UnsignedIntLit(ast::UintTy::U8)))
}
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitBool(value))
self.expr_lit(sp, ast::LitKind::Bool(value))
}
fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
@ -712,7 +713,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_addr_of(sp, self.expr_vec(sp, exprs))
}
fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitStr(s, ast::CookedStr))
self.expr_lit(sp, ast::LitKind::Str(s, ast::CookedStr))
}
fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> {
@ -1113,7 +1114,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn meta_name_value(&self,
sp: Span,
name: InternedString,
value: ast::Lit_)
value: ast::LitKind)
-> P<ast::MetaItem> {
P(respan(sp, ast::MetaNameValue(name, respan(sp, value))))
}

View File

@ -218,7 +218,7 @@ pub mod rt {
impl ToTokens for str {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit = ast::LitStr(
let lit = ast::LitKind::Str(
token::intern_and_get_ident(self), ast::CookedStr);
dummy_spanned(lit).to_tokens(cx)
}
@ -249,13 +249,13 @@ pub mod rt {
impl ToTokens for bool {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
dummy_spanned(ast::LitBool(*self)).to_tokens(cx)
dummy_spanned(ast::LitKind::Bool(*self)).to_tokens(cx)
}
}
impl ToTokens for char {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
dummy_spanned(ast::LitChar(*self)).to_tokens(cx)
dummy_spanned(ast::LitKind::Char(*self)).to_tokens(cx)
}
}
@ -268,7 +268,7 @@ pub mod rt {
} else {
*self
};
let lit = ast::LitInt(val as u64, ast::SignedIntLit($tag));
let lit = ast::LitKind::Int(val as u64, ast::SignedIntLit($tag));
let lit = P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Lit(P(dummy_spanned(lit))),
@ -290,7 +290,7 @@ pub mod rt {
(unsigned, $t:ty, $tag:expr) => (
impl ToTokens for $t {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag));
let lit = ast::LitKind::Int(*self as u64, ast::UnsignedIntLit($tag));
dummy_spanned(lit).to_tokens(cx)
}
}

View File

@ -187,7 +187,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
let filename = format!("{}", file.display());
cx.codemap().new_filemap_and_lines(&filename, "");
base::MacEager::expr(cx.expr_lit(sp, ast::LitByteStr(Rc::new(bytes))))
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Rc::new(bytes))))
}
}
}

View File

@ -175,7 +175,7 @@ impl<'a> Parser<'a> {
// FIXME #623 Non-string meta items are not serialized correctly;
// just forbid them for now
match lit.node {
ast::LitStr(..) => {}
ast::LitKind::Str(..) => {}
_ => {
self.span_err(lit.span,
"non-string literals are not allowed in meta-items");

View File

@ -449,11 +449,11 @@ fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool {
}
fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
sd: &Handler, sp: Span) -> ast::Lit_ {
sd: &Handler, sp: Span) -> ast::LitKind {
debug!("filtered_float_lit: {}, {:?}", data, suffix);
match suffix.as_ref().map(|s| &**s) {
Some("f32") => ast::LitFloat(data, ast::FloatTy::F32),
Some("f64") => ast::LitFloat(data, ast::FloatTy::F64),
Some("f32") => ast::LitKind::Float(data, ast::FloatTy::F32),
Some("f64") => ast::LitKind::Float(data, ast::FloatTy::F64),
Some(suf) => {
if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) {
// if it looks like a width, lets try to be helpful.
@ -466,13 +466,13 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
.emit();
}
ast::LitFloatUnsuffixed(data)
ast::LitKind::FloatUnsuffixed(data)
}
None => ast::LitFloatUnsuffixed(data)
None => ast::LitKind::FloatUnsuffixed(data)
}
}
pub fn float_lit(s: &str, suffix: Option<InternedString>,
sd: &Handler, sp: Span) -> ast::Lit_ {
sd: &Handler, sp: Span) -> ast::LitKind {
debug!("float_lit: {:?}, {:?}", s, suffix);
// FIXME #2252: bounds checking float literals is deferred until trans
let s = s.chars().filter(|&c| c != '_').collect::<String>();
@ -576,7 +576,7 @@ pub fn integer_lit(s: &str,
suffix: Option<InternedString>,
sd: &Handler,
sp: Span)
-> ast::Lit_ {
-> ast::LitKind {
// s can only be ascii, byte indexing is fine
let s2 = s.chars().filter(|&c| c != '_').collect::<String>();
@ -652,7 +652,7 @@ pub fn integer_lit(s: &str,
string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix);
match u64::from_str_radix(s, base) {
Ok(r) => ast::LitInt(r, ty),
Ok(r) => ast::LitKind::Int(r, ty),
Err(_) => {
// small bases are lexed as if they were base 10, e.g, the string
// might be `0b10201`. This will cause the conversion above to fail,
@ -665,7 +665,7 @@ pub fn integer_lit(s: &str,
if !already_errored {
sd.span_err(sp, "int literal is too large");
}
ast::LitInt(0, ty)
ast::LitKind::Int(0, ty)
}
}
}

View File

@ -27,9 +27,8 @@ use ast::{Ident, Inherited, ImplItem, Item, Item_, ItemStatic};
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl};
use ast::{ItemExternCrate, ItemUse};
use ast::{Lit, Lit_, UintTy};
use ast::{LitBool, LitChar, LitByte, LitByteStr};
use ast::{LitStr, LitInt, Local};
use ast::{Lit, LitKind, UintTy};
use ast::Local;
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
use ast::{MutImmutable, MutMutable, Mac_};
use ast::{MutTy, Mutability};
@ -1517,7 +1516,7 @@ impl<'a> Parser<'a> {
}
/// Matches token_lit = LIT_INTEGER | ...
pub fn lit_from_token(&self, tok: &token::Token) -> PResult<'a, Lit_> {
pub fn lit_from_token(&self, tok: &token::Token) -> PResult<'a, LitKind> {
match *tok {
token::Interpolated(token::NtExpr(ref v)) => {
match v.node {
@ -1527,8 +1526,8 @@ impl<'a> Parser<'a> {
}
token::Literal(lit, suf) => {
let (suffix_illegal, out) = match lit {
token::Byte(i) => (true, LitByte(parse::byte_lit(&i.as_str()).0)),
token::Char(i) => (true, LitChar(parse::char_lit(&i.as_str()).0)),
token::Byte(i) => (true, LitKind::Byte(parse::byte_lit(&i.as_str()).0)),
token::Char(i) => (true, LitKind::Char(parse::char_lit(&i.as_str()).0)),
// there are some valid suffixes for integer and
// float literals, so all the handling is done
@ -1548,20 +1547,20 @@ impl<'a> Parser<'a> {
token::Str_(s) => {
(true,
LitStr(token::intern_and_get_ident(&parse::str_lit(&s.as_str())),
ast::CookedStr))
LitKind::Str(token::intern_and_get_ident(&parse::str_lit(&s.as_str())),
ast::CookedStr))
}
token::StrRaw(s, n) => {
(true,
LitStr(
LitKind::Str(
token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())),
ast::RawStr(n)))
}
token::ByteStr(i) =>
(true, LitByteStr(parse::byte_str_lit(&i.as_str()))),
(true, LitKind::ByteStr(parse::byte_str_lit(&i.as_str()))),
token::ByteStrRaw(i, _) =>
(true,
LitByteStr(Rc::new(i.to_string().into_bytes()))),
LitKind::ByteStr(Rc::new(i.to_string().into_bytes()))),
};
if suffix_illegal {
@ -1579,9 +1578,9 @@ impl<'a> Parser<'a> {
pub fn parse_lit(&mut self) -> PResult<'a, Lit> {
let lo = self.span.lo;
let lit = if self.eat_keyword(keywords::True) {
LitBool(true)
LitKind::Bool(true)
} else if self.eat_keyword(keywords::False) {
LitBool(false)
LitKind::Bool(false)
} else {
let token = self.bump_and_get();
let lit = try!(self.lit_from_token(&token));
@ -2015,7 +2014,7 @@ impl<'a> Parser<'a> {
pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinAttributes) -> P<Expr> {
let span = &self.span;
let lv_lit = P(codemap::Spanned {
node: LitInt(i as u64, ast::UnsignedIntLit(UintTy::U32)),
node: LitKind::Int(i as u64, ast::UnsignedIntLit(UintTy::U32)),
span: *span
});

View File

@ -630,20 +630,20 @@ pub trait PrintState<'a> {
_ => ()
}
match lit.node {
ast::LitStr(ref st, style) => self.print_string(&st, style),
ast::LitByte(byte) => {
ast::LitKind::Str(ref st, style) => self.print_string(&st, style),
ast::LitKind::Byte(byte) => {
let mut res = String::from("b'");
res.extend(ascii::escape_default(byte).map(|c| c as char));
res.push('\'');
word(self.writer(), &res[..])
}
ast::LitChar(ch) => {
ast::LitKind::Char(ch) => {
let mut res = String::from("'");
res.extend(ch.escape_default());
res.push('\'');
word(self.writer(), &res[..])
}
ast::LitInt(i, t) => {
ast::LitKind::Int(i, t) => {
match t {
ast::SignedIntLit(st) => {
word(self.writer(),
@ -657,18 +657,18 @@ pub trait PrintState<'a> {
}
}
}
ast::LitFloat(ref f, t) => {
ast::LitKind::Float(ref f, t) => {
word(self.writer(),
&format!(
"{}{}",
&f,
t.ty_to_string()))
}
ast::LitFloatUnsuffixed(ref f) => word(self.writer(), &f[..]),
ast::LitBool(val) => {
ast::LitKind::FloatUnsuffixed(ref f) => word(self.writer(), &f[..]),
ast::LitKind::Bool(val) => {
if val { word(self.writer(), "true") } else { word(self.writer(), "false") }
}
ast::LitByteStr(ref v) => {
ast::LitKind::ByteStr(ref v) => {
let mut escaped: String = String::new();
for &ch in v.iter() {
escaped.extend(ascii::escape_default(ch)

View File

@ -29,24 +29,24 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
match e.node {
ast::ExprKind::Lit(ref lit) => {
match lit.node {
ast::LitStr(ref s, _) |
ast::LitFloat(ref s, _) |
ast::LitFloatUnsuffixed(ref s) => {
ast::LitKind::Str(ref s, _) |
ast::LitKind::Float(ref s, _) |
ast::LitKind::FloatUnsuffixed(ref s) => {
accumulator.push_str(&s);
}
ast::LitChar(c) => {
ast::LitKind::Char(c) => {
accumulator.push(c);
}
ast::LitInt(i, ast::UnsignedIntLit(_)) |
ast::LitInt(i, ast::SignedIntLit(_)) |
ast::LitInt(i, ast::UnsuffixedIntLit) => {
ast::LitKind::Int(i, ast::UnsignedIntLit(_)) |
ast::LitKind::Int(i, ast::SignedIntLit(_)) |
ast::LitKind::Int(i, ast::UnsuffixedIntLit) => {
accumulator.push_str(&format!("{}", i));
}
ast::LitBool(b) => {
ast::LitKind::Bool(b) => {
accumulator.push_str(&format!("{}", b));
}
ast::LitByte(..) |
ast::LitByteStr(..) => {
ast::LitKind::Byte(..) |
ast::LitKind::ByteStr(..) => {
cx.span_err(e.span, "cannot concatenate a byte string literal");
}
}

View File

@ -71,8 +71,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
// We want to make sure we have the expn_id set so that we can use unstable methods
let span = Span { expn_id: cx.backtrace(), .. span };
let name = cx.expr_lit(span, ast::Lit_::LitStr(ident.name.as_str(),
ast::StrStyle::CookedStr));
let name = cx.expr_lit(span, ast::LitKind::Str(ident.name.as_str(),
ast::StrStyle::CookedStr));
let builder = token::str_to_ident("builder");
let builder_expr = cx.expr_ident(span, builder.clone());
@ -112,7 +112,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr));
for field in fields {
let name = cx.expr_lit(field.span, ast::Lit_::LitStr(
let name = cx.expr_lit(field.span, ast::LitKind::Str(
field.name.unwrap().name.as_str(),
ast::StrStyle::CookedStr));

View File

@ -409,7 +409,7 @@ impl<'a, 'b> Context<'a, 'b> {
}
// Translate the format
let fill = self.ecx.expr_lit(sp, ast::LitChar(fill));
let fill = self.ecx.expr_lit(sp, ast::LitKind::Char(fill));
let align = |name| {
let mut p = Context::rtpath(self.ecx, "Alignment");
p.push(self.ecx.ident_of(name));