Skip to content

Implement isize/usize #20609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use syntax::ast_util::is_shift_binop;
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{Span, DUMMY_SP};
use syntax::parse::token;
use syntax::ast::{TyI, TyU, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
use syntax::ast_util;
use syntax::ptr::P;
use syntax::visit::{self, Visitor};
Expand Down Expand Up @@ -216,7 +216,7 @@ impl LintPass for TypeLimits {
match lit.node {
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => {
let int_type = if t == ast::TyI {
let int_type = if t == ast::TyIs {
cx.sess().target.int_type
} else { t };
let (min, max) = int_ty_range(int_type);
Expand All @@ -233,7 +233,7 @@ impl LintPass for TypeLimits {
};
},
ty::ty_uint(t) => {
let uint_type = if t == ast::TyU {
let uint_type = if t == ast::TyUs {
cx.sess().target.uint_type
} else { t };
let (min, max) = uint_ty_range(uint_type);
Expand Down Expand Up @@ -296,7 +296,7 @@ impl LintPass for TypeLimits {
// warnings are consistent between 32- and 64-bit platforms
fn int_ty_range(int_ty: ast::IntTy) -> (i64, i64) {
match int_ty {
ast::TyI => (i64::MIN, i64::MAX),
ast::TyIs=> (i64::MIN, i64::MAX),
ast::TyI8 => (i8::MIN as i64, i8::MAX as i64),
ast::TyI16 => (i16::MIN as i64, i16::MAX as i64),
ast::TyI32 => (i32::MIN as i64, i32::MAX as i64),
Expand All @@ -306,7 +306,7 @@ impl LintPass for TypeLimits {

fn uint_ty_range(uint_ty: ast::UintTy) -> (u64, u64) {
match uint_ty {
ast::TyU => (u64::MIN, u64::MAX),
ast::TyUs=> (u64::MIN, u64::MAX),
ast::TyU8 => (u8::MIN as u64, u8::MAX as u64),
ast::TyU16 => (u16::MIN as u64, u16::MAX as u64),
ast::TyU32 => (u32::MIN as u64, u32::MAX as u64),
Expand All @@ -323,7 +323,7 @@ impl LintPass for TypeLimits {

fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
match int_ty {
ast::TyI => int_ty_bits(target_int_ty, target_int_ty),
ast::TyIs=> int_ty_bits(target_int_ty, target_int_ty),
ast::TyI8 => i8::BITS as u64,
ast::TyI16 => i16::BITS as u64,
ast::TyI32 => i32::BITS as u64,
Expand All @@ -333,7 +333,7 @@ impl LintPass for TypeLimits {

fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
match uint_ty {
ast::TyU => uint_ty_bits(target_uint_ty, target_uint_ty),
ast::TyUs=> uint_ty_bits(target_uint_ty, target_uint_ty),
ast::TyU8 => u8::BITS as u64,
ast::TyU16 => u16::BITS as u64,
ast::TyU32 => u32::BITS as u64,
Expand Down Expand Up @@ -404,14 +404,14 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
match self.cx.tcx.def_map.borrow()[path_id].clone() {
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
def::DefPrimTy(ast::TyInt(ast::TyIs)) => {
self.cx.span_lint(IMPROPER_CTYPES, sp,
"found rust type `int` in foreign module, while \
"found rust type `isize` in foreign module, while \
libc::c_int or libc::c_long should be used");
}
def::DefPrimTy(ast::TyUint(ast::TyU)) => {
def::DefPrimTy(ast::TyUint(ast::TyUs)) => {
self.cx.span_lint(IMPROPER_CTYPES, sp,
"found rust type `uint` in foreign module, while \
"found rust type `usize` in foreign module, while \
libc::c_uint or libc::c_ulong should be used");
}
def::DefTy(..) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let tcx = st.tcx;
match next(st) {
'b' => return tcx.types.bool,
'i' => return tcx.types.int,
'u' => return tcx.types.uint,
'i' => { /* eat the s of is */ next(st); return tcx.types.int },
'u' => { /* eat the s of us */ next(st); return tcx.types.uint },
'M' => {
match next(st) {
'b' => return tcx.types.u8,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
ty::ty_char => mywrite!(w, "c"),
ty::ty_int(t) => {
match t {
ast::TyI => mywrite!(w, "i"),
ast::TyIs => mywrite!(w, "is"),
ast::TyI8 => mywrite!(w, "MB"),
ast::TyI16 => mywrite!(w, "MW"),
ast::TyI32 => mywrite!(w, "ML"),
Expand All @@ -70,7 +70,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
}
ty::ty_uint(t) => {
match t {
ast::TyU => mywrite!(w, "u"),
ast::TyUs => mywrite!(w, "us"),
ast::TyU8 => mywrite!(w, "Mb"),
ast::TyU16 => mywrite!(w, "Mw"),
ast::TyU32 => mywrite!(w, "Ml"),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St

eval_const_expr_partial(tcx, &**base)
.and_then(|val| define_casts!(val, {
ty::ty_int(ast::TyI) => (int, const_int, i64),
ty::ty_int(ast::TyIs) => (int, const_int, i64),
ty::ty_int(ast::TyI8) => (i8, const_int, i64),
ty::ty_int(ast::TyI16) => (i16, const_int, i64),
ty::ty_int(ast::TyI32) => (i32, const_int, i64),
ty::ty_int(ast::TyI64) => (i64, const_int, i64),
ty::ty_uint(ast::TyU) => (uint, const_uint, u64),
ty::ty_uint(ast::TyUs) => (uint, const_uint, u64),
ty::ty_uint(ast::TyU8) => (u8, const_uint, u64),
ty::ty_uint(ast::TyU16) => (u16, const_uint, u64),
ty::ty_uint(ast::TyU32) => (u32, const_uint, u64),
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2302,12 +2302,12 @@ impl<'tcx> CommonTypes<'tcx> {
bool: intern_ty(arena, interner, ty_bool),
char: intern_ty(arena, interner, ty_char),
err: intern_ty(arena, interner, ty_err),
int: intern_ty(arena, interner, ty_int(ast::TyI)),
int: intern_ty(arena, interner, ty_int(ast::TyIs)),
i8: intern_ty(arena, interner, ty_int(ast::TyI8)),
i16: intern_ty(arena, interner, ty_int(ast::TyI16)),
i32: intern_ty(arena, interner, ty_int(ast::TyI32)),
i64: intern_ty(arena, interner, ty_int(ast::TyI64)),
uint: intern_ty(arena, interner, ty_uint(ast::TyU)),
uint: intern_ty(arena, interner, ty_uint(ast::TyUs)),
u8: intern_ty(arena, interner, ty_uint(ast::TyU8)),
u16: intern_ty(arena, interner, ty_uint(ast::TyU16)),
u32: intern_ty(arena, interner, ty_uint(ast::TyU32)),
Expand Down Expand Up @@ -2653,7 +2653,7 @@ impl FlagComputation {

pub fn mk_mach_int<'tcx>(tcx: &ctxt<'tcx>, tm: ast::IntTy) -> Ty<'tcx> {
match tm {
ast::TyI => tcx.types.int,
ast::TyIs => tcx.types.int,
ast::TyI8 => tcx.types.i8,
ast::TyI16 => tcx.types.i16,
ast::TyI32 => tcx.types.i32,
Expand All @@ -2663,7 +2663,7 @@ pub fn mk_mach_int<'tcx>(tcx: &ctxt<'tcx>, tm: ast::IntTy) -> Ty<'tcx> {

pub fn mk_mach_uint<'tcx>(tcx: &ctxt<'tcx>, tm: ast::UintTy) -> Ty<'tcx> {
match tm {
ast::TyU => tcx.types.uint,
ast::TyUs => tcx.types.uint,
ast::TyU8 => tcx.types.u8,
ast::TyU16 => tcx.types.u16,
ast::TyU32 => tcx.types.u32,
Expand Down Expand Up @@ -3324,7 +3324,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {

let result = match ty.sty {
// uint and int are ffi-unsafe
ty_uint(ast::TyU) | ty_int(ast::TyI) => {
ty_uint(ast::TyUs) | ty_int(ast::TyIs) => {
TC::ReachesFfiUnsafe
}

Expand Down Expand Up @@ -3896,7 +3896,7 @@ pub fn type_is_fresh(ty: Ty) -> bool {

pub fn type_is_uint(ty: Ty) -> bool {
match ty.sty {
ty_infer(IntVar(_)) | ty_uint(ast::TyU) => true,
ty_infer(IntVar(_)) | ty_uint(ast::TyUs) => true,
_ => false
}
}
Expand Down Expand Up @@ -3942,7 +3942,7 @@ pub fn type_is_signed(ty: Ty) -> bool {

pub fn type_is_machine(ty: Ty) -> bool {
match ty.sty {
ty_int(ast::TyI) | ty_uint(ast::TyU) => false,
ty_int(ast::TyIs) | ty_uint(ast::TyUs) => false,
ty_int(..) | ty_uint(..) | ty_float(..) => true,
_ => false
}
Expand Down
10 changes: 6 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ use syntax::ast::{PolyTraitRef, PrimTy, SelfExplicit};
use syntax::ast::{RegionTyParamBound, StructField};
use syntax::ast::{TraitRef, TraitTyParamBound};
use syntax::ast::{Ty, TyBool, TyChar, TyF32};
use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt, TyObjectSum};
use syntax::ast::{TyF64, TyFloat, TyIs, TyI8, TyI16, TyI32, TyI64, TyInt, TyObjectSum};
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyPolyTraitRef, TyQPath};
use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint};
use syntax::ast::{TyRptr, TyStr, TyUs, TyU8, TyU16, TyU32, TyU64, TyUint};
use syntax::ast::{TypeImplItem};
use syntax::ast;
use syntax::ast_map;
Expand Down Expand Up @@ -833,13 +833,15 @@ impl PrimitiveTypeTable {
table.intern("char", TyChar);
table.intern("f32", TyFloat(TyF32));
table.intern("f64", TyFloat(TyF64));
table.intern("int", TyInt(TyI));
table.intern("int", TyInt(TyIs));
table.intern("isize", TyInt(TyIs));
table.intern("i8", TyInt(TyI8));
table.intern("i16", TyInt(TyI16));
table.intern("i32", TyInt(TyI32));
table.intern("i64", TyInt(TyI64));
table.intern("str", TyStr);
table.intern("uint", TyUint(TyU));
table.intern("uint", TyUint(TyUs));
table.intern("usize", TyUint(TyUs));
table.intern("u8", TyUint(TyU8));
table.intern("u16", TyUint(TyU16));
table.intern("u32", TyUint(TyU32));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
ty::ty_int(t) => {
let llty = Type::int_from_ty(cx.ccx(), t);
let min = match t {
ast::TyI if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
ast::TyI => i64::MIN as u64,
ast::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
ast::TyIs => i64::MIN as u64,
ast::TyI8 => i8::MIN as u64,
ast::TyI16 => i16::MIN as u64,
ast::TyI32 => i32::MIN as u64,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_trans/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,14 +1797,14 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
ty::ty_bool => ("bool".to_string(), DW_ATE_boolean),
ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char),
ty::ty_int(int_ty) => match int_ty {
ast::TyI => ("int".to_string(), DW_ATE_signed),
ast::TyIs => ("isize".to_string(), DW_ATE_signed),
ast::TyI8 => ("i8".to_string(), DW_ATE_signed),
ast::TyI16 => ("i16".to_string(), DW_ATE_signed),
ast::TyI32 => ("i32".to_string(), DW_ATE_signed),
ast::TyI64 => ("i64".to_string(), DW_ATE_signed)
},
ty::ty_uint(uint_ty) => match uint_ty {
ast::TyU => ("uint".to_string(), DW_ATE_unsigned),
ast::TyUs => ("usize".to_string(), DW_ATE_unsigned),
ast::TyU8 => ("u8".to_string(), DW_ATE_unsigned),
ast::TyU16 => ("u16".to_string(), DW_ATE_unsigned),
ast::TyU32 => ("u32".to_string(), DW_ATE_unsigned),
Expand Down Expand Up @@ -3729,12 +3729,12 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
ty::ty_bool => output.push_str("bool"),
ty::ty_char => output.push_str("char"),
ty::ty_str => output.push_str("str"),
ty::ty_int(ast::TyI) => output.push_str("int"),
ty::ty_int(ast::TyIs) => output.push_str("isize"),
ty::ty_int(ast::TyI8) => output.push_str("i8"),
ty::ty_int(ast::TyI16) => output.push_str("i16"),
ty::ty_int(ast::TyI32) => output.push_str("i32"),
ty::ty_int(ast::TyI64) => output.push_str("i64"),
ty::ty_uint(ast::TyU) => output.push_str("uint"),
ty::ty_uint(ast::TyUs) => output.push_str("usize"),
ty::ty_uint(ast::TyU8) => output.push_str("u8"),
ty::ty_uint(ast::TyU16) => output.push_str("u16"),
ty::ty_uint(ast::TyU32) => output.push_str("u32"),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Type {

pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
match t {
ast::TyI => ccx.int_type(),
ast::TyIs => ccx.int_type(),
ast::TyI8 => Type::i8(ccx),
ast::TyI16 => Type::i16(ccx),
ast::TyI32 => Type::i32(ccx),
Expand All @@ -122,7 +122,7 @@ impl Type {

pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
match t {
ast::TyU => ccx.int_type(),
ast::TyUs => ccx.int_type(),
ast::TyU8 => Type::i8(ccx),
ast::TyU16 => Type::i16(ccx),
ast::TyU32 => Type::i32(ccx),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type {
}

match unsized_part_of_type(cx.tcx(), t).sty {
ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyU),
ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyUs),
ty::ty_trait(_) => Type::vtable_ptr(cx),
_ => panic!("Unexpected type returned from unsized_part_of_type : {}",
t.repr(cx.tcx()))
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4859,7 +4859,7 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
ast::TyU16 => disr as u16 as Disr == disr,
ast::TyU32 => disr as u32 as Disr == disr,
ast::TyU64 => disr as u64 as Disr == disr,
ast::TyU => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr)
ast::TyUs => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr)
}
}
fn int_in_range(ccx: &CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool {
Expand All @@ -4868,7 +4868,7 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
ast::TyI16 => disr as i16 as Disr == disr,
ast::TyI32 => disr as i32 as Disr == disr,
ast::TyI64 => disr as i64 as Disr == disr,
ast::TyI => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr)
ast::TyIs => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr)
}
}
match ty {
Expand Down
20 changes: 10 additions & 10 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,8 @@ pub enum Type {

#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Copy)]
pub enum PrimitiveType {
Int, I8, I16, I32, I64,
Uint, U8, U16, U32, U64,
Isize, I8, I16, I32, I64,
Usize, U8, U16, U32, U64,
F32, F64,
Char,
Bool,
Expand All @@ -1264,12 +1264,12 @@ pub enum TypeKind {
impl PrimitiveType {
fn from_str(s: &str) -> Option<PrimitiveType> {
match s.as_slice() {
"int" => Some(Int),
"isize" | "int" => Some(Isize),
"i8" => Some(I8),
"i16" => Some(I16),
"i32" => Some(I32),
"i64" => Some(I64),
"uint" => Some(Uint),
"usize" | "uint" => Some(Usize),
"u8" => Some(U8),
"u16" => Some(U16),
"u32" => Some(U32),
Expand Down Expand Up @@ -1308,12 +1308,12 @@ impl PrimitiveType {

pub fn to_string(&self) -> &'static str {
match *self {
Int => "int",
Isize => "isize",
I8 => "i8",
I16 => "i16",
I32 => "i32",
I64 => "i64",
Uint => "uint",
Usize => "usize",
U8 => "u8",
U16 => "u16",
U32 => "u32",
Expand Down Expand Up @@ -1387,12 +1387,12 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
match self.sty {
ty::ty_bool => Primitive(Bool),
ty::ty_char => Primitive(Char),
ty::ty_int(ast::TyI) => Primitive(Int),
ty::ty_int(ast::TyIs) => Primitive(Isize),
ty::ty_int(ast::TyI8) => Primitive(I8),
ty::ty_int(ast::TyI16) => Primitive(I16),
ty::ty_int(ast::TyI32) => Primitive(I32),
ty::ty_int(ast::TyI64) => Primitive(I64),
ty::ty_uint(ast::TyU) => Primitive(Uint),
ty::ty_uint(ast::TyUs) => Primitive(Usize),
ty::ty_uint(ast::TyU8) => Primitive(U8),
ty::ty_uint(ast::TyU16) => Primitive(U16),
ty::ty_uint(ast::TyU32) => Primitive(U32),
Expand Down Expand Up @@ -2265,12 +2265,12 @@ fn resolve_type(cx: &DocContext,
ast::TyStr => return Primitive(Str),
ast::TyBool => return Primitive(Bool),
ast::TyChar => return Primitive(Char),
ast::TyInt(ast::TyI) => return Primitive(Int),
ast::TyInt(ast::TyIs) => return Primitive(Isize),
ast::TyInt(ast::TyI8) => return Primitive(I8),
ast::TyInt(ast::TyI16) => return Primitive(I16),
ast::TyInt(ast::TyI32) => return Primitive(I32),
ast::TyInt(ast::TyI64) => return Primitive(I64),
ast::TyUint(ast::TyU) => return Primitive(Uint),
ast::TyUint(ast::TyUs) => return Primitive(Usize),
ast::TyUint(ast::TyU8) => return Primitive(U8),
ast::TyUint(ast::TyU16) => return Primitive(U16),
ast::TyUint(ast::TyU32) => return Primitive(U32),
Expand Down
Loading