Skip to content

Commit

Permalink
[breaking-change] don't pub export ast::Lit_ variants
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 11, 2016
1 parent 05d4cef commit 69072c4
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -1322,30 +1322,30 @@ 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 {
// FIXME(#31407) this is only necessary because float parsing is buggy
sess.span_bug(span, "could not evaluate float literal (see issue #31407)");
}
}
ast::LitBool(b) => Bool(b)
ast::LitKind::Bool(b) => Bool(b)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/svh.rs
Expand Up @@ -232,7 +232,7 @@ mod svh_visitor {
SawExprTup,
SawExprBinary(hir::BinOp_),
SawExprUnary(hir::UnOp),
SawExprLit(ast::Lit_),
SawExprLit(ast::LitKind),
SawExprCast,
SawExprType,
SawExprIf,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Expand Up @@ -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,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Expand Up @@ -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 { ... }");
}
Expand Down
25 changes: 13 additions & 12 deletions src/librustc_lint/types.rs
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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!()
Expand All @@ -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!()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_trans/trans/consts.rs
Expand Up @@ -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;
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/expr.rs
Expand Up @@ -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)
}
_ => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/tvec.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/_match.rs
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -2531,21 +2531,21 @@ 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);
}
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(),
}
}

Expand Down
25 changes: 12 additions & 13 deletions src/libsyntax/ast.rs
Expand Up @@ -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_::*;
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
Expand Down

0 comments on commit 69072c4

Please sign in to comment.