Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[breaking-change] don't glob export ast::{UintTy, IntTy} variants
  • Loading branch information
oli-obk committed Feb 11, 2016
1 parent ccf48bc commit 625e78b
Show file tree
Hide file tree
Showing 33 changed files with 404 additions and 407 deletions.
60 changes: 30 additions & 30 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -545,34 +545,34 @@ pub enum UintTy { U8, U16, U32, U64 }

impl IntTy {
pub fn from(tcx: &ty::ctxt, t: ast::IntTy) -> IntTy {
let t = if let ast::TyIs = t {
let t = if let ast::IntTy::Is = t {
tcx.sess.target.int_type
} else {
t
};
match t {
ast::TyIs => unreachable!(),
ast::TyI8 => IntTy::I8,
ast::TyI16 => IntTy::I16,
ast::TyI32 => IntTy::I32,
ast::TyI64 => IntTy::I64,
ast::IntTy::Is => unreachable!(),
ast::IntTy::I8 => IntTy::I8,
ast::IntTy::I16 => IntTy::I16,
ast::IntTy::I32 => IntTy::I32,
ast::IntTy::I64 => IntTy::I64,
}
}
}

impl UintTy {
pub fn from(tcx: &ty::ctxt, t: ast::UintTy) -> UintTy {
let t = if let ast::TyUs = t {
let t = if let ast::UintTy::Us = t {
tcx.sess.target.uint_type
} else {
t
};
match t {
ast::TyUs => unreachable!(),
ast::TyU8 => UintTy::U8,
ast::TyU16 => UintTy::U16,
ast::TyU32 => UintTy::U32,
ast::TyU64 => UintTy::U64,
ast::UintTy::Us => unreachable!(),
ast::UintTy::U8 => UintTy::U8,
ast::UintTy::U16 => UintTy::U16,
ast::UintTy::U32 => UintTy::U32,
ast::UintTy::U64 => UintTy::U64,
}
}
}
Expand Down Expand Up @@ -1289,30 +1289,30 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {

// Issue #23890: If isize/usize, then dispatch to appropriate target representation type
match (&ty.sty, tcx.sess.target.int_type, tcx.sess.target.uint_type) {
(&ty::TyInt(ast::TyIs), ast::TyI32, _) => return convert_val!(i32, Int, i64),
(&ty::TyInt(ast::TyIs), ast::TyI64, _) => return convert_val!(i64, Int, i64),
(&ty::TyInt(ast::TyIs), _, _) => panic!("unexpected target.int_type"),
(&ty::TyInt(ast::IntTy::Is), ast::IntTy::I32, _) => return convert_val!(i32, Int, i64),
(&ty::TyInt(ast::IntTy::Is), ast::IntTy::I64, _) => return convert_val!(i64, Int, i64),
(&ty::TyInt(ast::IntTy::Is), _, _) => panic!("unexpected target.int_type"),

(&ty::TyUint(ast::TyUs), _, ast::TyU32) => return convert_val!(u32, Uint, u64),
(&ty::TyUint(ast::TyUs), _, ast::TyU64) => return convert_val!(u64, Uint, u64),
(&ty::TyUint(ast::TyUs), _, _) => panic!("unexpected target.uint_type"),
(&ty::TyUint(ast::UintTy::Us), _, ast::UintTy::U32) => return convert_val!(u32, Uint, u64),
(&ty::TyUint(ast::UintTy::Us), _, ast::UintTy::U64) => return convert_val!(u64, Uint, u64),
(&ty::TyUint(ast::UintTy::Us), _, _) => panic!("unexpected target.uint_type"),

_ => {}
}

match ty.sty {
ty::TyInt(ast::TyIs) => unreachable!(),
ty::TyUint(ast::TyUs) => unreachable!(),

ty::TyInt(ast::TyI8) => convert_val!(i8, Int, i64),
ty::TyInt(ast::TyI16) => convert_val!(i16, Int, i64),
ty::TyInt(ast::TyI32) => convert_val!(i32, Int, i64),
ty::TyInt(ast::TyI64) => convert_val!(i64, Int, i64),

ty::TyUint(ast::TyU8) => convert_val!(u8, Uint, u64),
ty::TyUint(ast::TyU16) => convert_val!(u16, Uint, u64),
ty::TyUint(ast::TyU32) => convert_val!(u32, Uint, u64),
ty::TyUint(ast::TyU64) => convert_val!(u64, Uint, u64),
ty::TyInt(ast::IntTy::Is) => unreachable!(),
ty::TyUint(ast::UintTy::Us) => unreachable!(),

ty::TyInt(ast::IntTy::I8) => convert_val!(i8, Int, i64),
ty::TyInt(ast::IntTy::I16) => convert_val!(i16, Int, i64),
ty::TyInt(ast::IntTy::I32) => convert_val!(i32, Int, i64),
ty::TyInt(ast::IntTy::I64) => convert_val!(i64, Int, i64),

ty::TyUint(ast::UintTy::U8) => convert_val!(u8, Uint, u64),
ty::TyUint(ast::UintTy::U16) => convert_val!(u16, Uint, u64),
ty::TyUint(ast::UintTy::U32) => convert_val!(u32, Uint, u64),
ty::TyUint(ast::UintTy::U64) => convert_val!(u64, Uint, u64),

ty::TyFloat(ast::FloatTy::F32) => convert_val!(f32, Float, f64),
ty::TyFloat(ast::FloatTy::F64) => convert_val!(f64, Float, f64),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty/contents.rs
Expand Up @@ -180,7 +180,7 @@ impl<'tcx> ty::TyS<'tcx> {

let result = match ty.sty {
// usize and isize are ffi-unsafe
ty::TyUint(ast::TyUs) | ty::TyInt(ast::TyIs) => {
ty::TyUint(ast::UintTy::Us) | ty::TyInt(ast::IntTy::Is) => {
TC::None
}

Expand Down
40 changes: 20 additions & 20 deletions src/librustc/middle/ty/context.rs
Expand Up @@ -192,16 +192,16 @@ impl<'tcx> CommonTypes<'tcx> {
bool: mk(TyBool),
char: mk(TyChar),
err: mk(TyError),
isize: mk(TyInt(ast::TyIs)),
i8: mk(TyInt(ast::TyI8)),
i16: mk(TyInt(ast::TyI16)),
i32: mk(TyInt(ast::TyI32)),
i64: mk(TyInt(ast::TyI64)),
usize: mk(TyUint(ast::TyUs)),
u8: mk(TyUint(ast::TyU8)),
u16: mk(TyUint(ast::TyU16)),
u32: mk(TyUint(ast::TyU32)),
u64: mk(TyUint(ast::TyU64)),
isize: mk(TyInt(ast::IntTy::Is)),
i8: mk(TyInt(ast::IntTy::I8)),
i16: mk(TyInt(ast::IntTy::I16)),
i32: mk(TyInt(ast::IntTy::I32)),
i64: mk(TyInt(ast::IntTy::I64)),
usize: mk(TyUint(ast::UintTy::Us)),
u8: mk(TyUint(ast::UintTy::U8)),
u16: mk(TyUint(ast::UintTy::U16)),
u32: mk(TyUint(ast::UintTy::U32)),
u64: mk(TyUint(ast::UintTy::U64)),
f32: mk(TyFloat(ast::FloatTy::F32)),
f64: mk(TyFloat(ast::FloatTy::F64)),
}
Expand Down Expand Up @@ -840,21 +840,21 @@ impl<'tcx> ctxt<'tcx> {

pub fn mk_mach_int(&self, tm: ast::IntTy) -> Ty<'tcx> {
match tm {
ast::TyIs => self.types.isize,
ast::TyI8 => self.types.i8,
ast::TyI16 => self.types.i16,
ast::TyI32 => self.types.i32,
ast::TyI64 => self.types.i64,
ast::IntTy::Is => self.types.isize,
ast::IntTy::I8 => self.types.i8,
ast::IntTy::I16 => self.types.i16,
ast::IntTy::I32 => self.types.i32,
ast::IntTy::I64 => self.types.i64,
}
}

pub fn mk_mach_uint(&self, tm: ast::UintTy) -> Ty<'tcx> {
match tm {
ast::TyUs => self.types.usize,
ast::TyU8 => self.types.u8,
ast::TyU16 => self.types.u16,
ast::TyU32 => self.types.u32,
ast::TyU64 => self.types.u64,
ast::UintTy::Us => self.types.usize,
ast::UintTy::U8 => self.types.u8,
ast::UintTy::U16 => self.types.u16,
ast::UintTy::U32 => self.types.u32,
ast::UintTy::U64 => self.types.u64,
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty/sty.rs
Expand Up @@ -977,7 +977,7 @@ impl<'tcx> TyS<'tcx> {
pub fn sequence_element_type(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
match self.sty {
TyArray(ty, _) | TySlice(ty) => ty,
TyStr => cx.mk_mach_uint(ast::TyU8),
TyStr => cx.mk_mach_uint(ast::UintTy::U8),
_ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}",
self)),
}
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<'tcx> TyS<'tcx> {

pub fn is_uint(&self) -> bool {
match self.sty {
TyInfer(IntVar(_)) | TyUint(ast::TyUs) => true,
TyInfer(IntVar(_)) | TyUint(ast::UintTy::Us) => true,
_ => false
}
}
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl<'tcx> TyS<'tcx> {

pub fn is_machine(&self) -> bool {
match self.sty {
TyInt(ast::TyIs) | TyUint(ast::TyUs) => false,
TyInt(ast::IntTy::Is) | TyUint(ast::UintTy::Us) => false,
TyInt(..) | TyUint(..) | TyFloat(..) => true,
_ => false
}
Expand Down
138 changes: 69 additions & 69 deletions src/librustc/middle/ty/util.rs
Expand Up @@ -44,48 +44,48 @@ pub trait IntTypeExt {
impl IntTypeExt for attr::IntType {
fn to_ty<'tcx>(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
match *self {
SignedInt(ast::TyI8) => cx.types.i8,
SignedInt(ast::TyI16) => cx.types.i16,
SignedInt(ast::TyI32) => cx.types.i32,
SignedInt(ast::TyI64) => cx.types.i64,
SignedInt(ast::TyIs) => cx.types.isize,
UnsignedInt(ast::TyU8) => cx.types.u8,
UnsignedInt(ast::TyU16) => cx.types.u16,
UnsignedInt(ast::TyU32) => cx.types.u32,
UnsignedInt(ast::TyU64) => cx.types.u64,
UnsignedInt(ast::TyUs) => cx.types.usize,
SignedInt(ast::IntTy::I8) => cx.types.i8,
SignedInt(ast::IntTy::I16) => cx.types.i16,
SignedInt(ast::IntTy::I32) => cx.types.i32,
SignedInt(ast::IntTy::I64) => cx.types.i64,
SignedInt(ast::IntTy::Is) => cx.types.isize,
UnsignedInt(ast::UintTy::U8) => cx.types.u8,
UnsignedInt(ast::UintTy::U16) => cx.types.u16,
UnsignedInt(ast::UintTy::U32) => cx.types.u32,
UnsignedInt(ast::UintTy::U64) => cx.types.u64,
UnsignedInt(ast::UintTy::Us) => cx.types.usize,
}
}

fn i64_to_disr(&self, val: i64) -> Option<Disr> {
match *self {
SignedInt(ast::TyI8) => val.to_i8() .map(|v| v as Disr),
SignedInt(ast::TyI16) => val.to_i16() .map(|v| v as Disr),
SignedInt(ast::TyI32) => val.to_i32() .map(|v| v as Disr),
SignedInt(ast::TyI64) => val.to_i64() .map(|v| v as Disr),
UnsignedInt(ast::TyU8) => val.to_u8() .map(|v| v as Disr),
UnsignedInt(ast::TyU16) => val.to_u16() .map(|v| v as Disr),
UnsignedInt(ast::TyU32) => val.to_u32() .map(|v| v as Disr),
UnsignedInt(ast::TyU64) => val.to_u64() .map(|v| v as Disr),

UnsignedInt(ast::TyUs) |
SignedInt(ast::TyIs) => unreachable!(),
SignedInt(ast::IntTy::I8) => val.to_i8() .map(|v| v as Disr),
SignedInt(ast::IntTy::I16) => val.to_i16() .map(|v| v as Disr),
SignedInt(ast::IntTy::I32) => val.to_i32() .map(|v| v as Disr),
SignedInt(ast::IntTy::I64) => val.to_i64() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U8) => val.to_u8() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U16) => val.to_u16() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U32) => val.to_u32() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U64) => val.to_u64() .map(|v| v as Disr),

UnsignedInt(ast::UintTy::Us) |
SignedInt(ast::IntTy::Is) => unreachable!(),
}
}

fn u64_to_disr(&self, val: u64) -> Option<Disr> {
match *self {
SignedInt(ast::TyI8) => val.to_i8() .map(|v| v as Disr),
SignedInt(ast::TyI16) => val.to_i16() .map(|v| v as Disr),
SignedInt(ast::TyI32) => val.to_i32() .map(|v| v as Disr),
SignedInt(ast::TyI64) => val.to_i64() .map(|v| v as Disr),
UnsignedInt(ast::TyU8) => val.to_u8() .map(|v| v as Disr),
UnsignedInt(ast::TyU16) => val.to_u16() .map(|v| v as Disr),
UnsignedInt(ast::TyU32) => val.to_u32() .map(|v| v as Disr),
UnsignedInt(ast::TyU64) => val.to_u64() .map(|v| v as Disr),

UnsignedInt(ast::TyUs) |
SignedInt(ast::TyIs) => unreachable!(),
SignedInt(ast::IntTy::I8) => val.to_i8() .map(|v| v as Disr),
SignedInt(ast::IntTy::I16) => val.to_i16() .map(|v| v as Disr),
SignedInt(ast::IntTy::I32) => val.to_i32() .map(|v| v as Disr),
SignedInt(ast::IntTy::I64) => val.to_i64() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U8) => val.to_u8() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U16) => val.to_u16() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U32) => val.to_u32() .map(|v| v as Disr),
UnsignedInt(ast::UintTy::U64) => val.to_u64() .map(|v| v as Disr),

UnsignedInt(ast::UintTy::Us) |
SignedInt(ast::IntTy::Is) => unreachable!(),
}
}

Expand All @@ -97,18 +97,18 @@ impl IntTypeExt for attr::IntType {
// SignedInt repr means we *want* to reinterpret the bits
// treating the highest bit of Disr as a sign-bit, so
// cast to i64 before range-checking.
SignedInt(ast::TyI8) => add1!((val as i64).to_i8()),
SignedInt(ast::TyI16) => add1!((val as i64).to_i16()),
SignedInt(ast::TyI32) => add1!((val as i64).to_i32()),
SignedInt(ast::TyI64) => add1!(Some(val as i64)),

UnsignedInt(ast::TyU8) => add1!(val.to_u8()),
UnsignedInt(ast::TyU16) => add1!(val.to_u16()),
UnsignedInt(ast::TyU32) => add1!(val.to_u32()),
UnsignedInt(ast::TyU64) => add1!(Some(val)),

UnsignedInt(ast::TyUs) |
SignedInt(ast::TyIs) => unreachable!(),
SignedInt(ast::IntTy::I8) => add1!((val as i64).to_i8()),
SignedInt(ast::IntTy::I16) => add1!((val as i64).to_i16()),
SignedInt(ast::IntTy::I32) => add1!((val as i64).to_i32()),
SignedInt(ast::IntTy::I64) => add1!(Some(val as i64)),

UnsignedInt(ast::UintTy::U8) => add1!(val.to_u8()),
UnsignedInt(ast::UintTy::U16) => add1!(val.to_u16()),
UnsignedInt(ast::UintTy::U32) => add1!(val.to_u32()),
UnsignedInt(ast::UintTy::U64) => add1!(Some(val)),

UnsignedInt(ast::UintTy::Us) |
SignedInt(ast::IntTy::Is) => unreachable!(),
}
}

Expand All @@ -117,17 +117,17 @@ impl IntTypeExt for attr::IntType {
// full range from `i64::MIN` through `u64::MAX`.
fn disr_string(&self, val: Disr) -> String {
match *self {
SignedInt(ast::TyI8) => format!("{}", val as i8 ),
SignedInt(ast::TyI16) => format!("{}", val as i16),
SignedInt(ast::TyI32) => format!("{}", val as i32),
SignedInt(ast::TyI64) => format!("{}", val as i64),
UnsignedInt(ast::TyU8) => format!("{}", val as u8 ),
UnsignedInt(ast::TyU16) => format!("{}", val as u16),
UnsignedInt(ast::TyU32) => format!("{}", val as u32),
UnsignedInt(ast::TyU64) => format!("{}", val as u64),

UnsignedInt(ast::TyUs) |
SignedInt(ast::TyIs) => unreachable!(),
SignedInt(ast::IntTy::I8) => format!("{}", val as i8 ),
SignedInt(ast::IntTy::I16) => format!("{}", val as i16),
SignedInt(ast::IntTy::I32) => format!("{}", val as i32),
SignedInt(ast::IntTy::I64) => format!("{}", val as i64),
UnsignedInt(ast::UintTy::U8) => format!("{}", val as u8 ),
UnsignedInt(ast::UintTy::U16) => format!("{}", val as u16),
UnsignedInt(ast::UintTy::U32) => format!("{}", val as u32),
UnsignedInt(ast::UintTy::U64) => format!("{}", val as u64),

UnsignedInt(ast::UintTy::Us) |
SignedInt(ast::IntTy::Is) => unreachable!(),
}
}

Expand All @@ -137,17 +137,17 @@ impl IntTypeExt for attr::IntType {
}
let val = val.unwrap_or(ty::INITIAL_DISCRIMINANT_VALUE);
match *self {
SignedInt(ast::TyI8) => add1!(val as i8 ),
SignedInt(ast::TyI16) => add1!(val as i16),
SignedInt(ast::TyI32) => add1!(val as i32),
SignedInt(ast::TyI64) => add1!(val as i64),
UnsignedInt(ast::TyU8) => add1!(val as u8 ),
UnsignedInt(ast::TyU16) => add1!(val as u16),
UnsignedInt(ast::TyU32) => add1!(val as u32),
UnsignedInt(ast::TyU64) => add1!(val as u64),

UnsignedInt(ast::TyUs) |
SignedInt(ast::TyIs) => unreachable!(),
SignedInt(ast::IntTy::I8) => add1!(val as i8 ),
SignedInt(ast::IntTy::I16) => add1!(val as i16),
SignedInt(ast::IntTy::I32) => add1!(val as i32),
SignedInt(ast::IntTy::I64) => add1!(val as i64),
UnsignedInt(ast::UintTy::U8) => add1!(val as u8 ),
UnsignedInt(ast::UintTy::U16) => add1!(val as u16),
UnsignedInt(ast::UintTy::U32) => add1!(val as u32),
UnsignedInt(ast::UintTy::U64) => add1!(val as u64),

UnsignedInt(ast::UintTy::Us) |
SignedInt(ast::IntTy::Is) => unreachable!(),
}
}
}
Expand Down Expand Up @@ -279,14 +279,14 @@ impl<'tcx> ty::ctxt<'tcx> {
//
// NB. Historically `fn enum_variants` generate i64 here, while
// rustc_typeck::check would generate isize.
_ => SignedInt(ast::TyIs),
_ => SignedInt(ast::IntTy::Is),
};

let repr_type_ty = repr_type.to_ty(self);
let repr_type = match repr_type {
SignedInt(ast::TyIs) =>
SignedInt(ast::IntTy::Is) =>
SignedInt(self.sess.target.int_type),
UnsignedInt(ast::TyUs) =>
UnsignedInt(ast::UintTy::Us) =>
UnsignedInt(self.sess.target.uint_type),
other => other
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/config.rs
Expand Up @@ -728,8 +728,8 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
};

let (int_type, uint_type) = match &target.target_pointer_width[..] {
"32" => (ast::TyI32, ast::TyU32),
"64" => (ast::TyI64, ast::TyU64),
"32" => (ast::IntTy::I32, ast::UintTy::U32),
"64" => (ast::IntTy::I64, ast::UintTy::U64),
w => panic!(sp.fatal(&format!("target specification was invalid: \
unrecognized target-pointer-width {}", w))),
};
Expand Down

0 comments on commit 625e78b

Please sign in to comment.