Skip to content

Commit abcbe27

Browse files
committed
syntax/rustc: implement isize/usize
1 parent 6539cb4 commit abcbe27

File tree

22 files changed

+81
-78
lines changed

22 files changed

+81
-78
lines changed

src/librustc/lint/builtin.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use syntax::ast_util::is_shift_binop;
4646
use syntax::attr::{self, AttrMetaMethods};
4747
use syntax::codemap::{Span, DUMMY_SP};
4848
use syntax::parse::token;
49-
use syntax::ast::{TyI, TyU, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
49+
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
5050
use syntax::ast_util;
5151
use syntax::ptr::P;
5252
use syntax::visit::{self, Visitor};
@@ -216,7 +216,7 @@ impl LintPass for TypeLimits {
216216
match lit.node {
217217
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
218218
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => {
219-
let int_type = if t == ast::TyI {
219+
let int_type = if t == ast::TyIs {
220220
cx.sess().target.int_type
221221
} else { t };
222222
let (min, max) = int_ty_range(int_type);
@@ -233,7 +233,7 @@ impl LintPass for TypeLimits {
233233
};
234234
},
235235
ty::ty_uint(t) => {
236-
let uint_type = if t == ast::TyU {
236+
let uint_type = if t == ast::TyUs {
237237
cx.sess().target.uint_type
238238
} else { t };
239239
let (min, max) = uint_ty_range(uint_type);
@@ -296,7 +296,7 @@ impl LintPass for TypeLimits {
296296
// warnings are consistent between 32- and 64-bit platforms
297297
fn int_ty_range(int_ty: ast::IntTy) -> (i64, i64) {
298298
match int_ty {
299-
ast::TyI => (i64::MIN, i64::MAX),
299+
ast::TyIs=> (i64::MIN, i64::MAX),
300300
ast::TyI8 => (i8::MIN as i64, i8::MAX as i64),
301301
ast::TyI16 => (i16::MIN as i64, i16::MAX as i64),
302302
ast::TyI32 => (i32::MIN as i64, i32::MAX as i64),
@@ -306,7 +306,7 @@ impl LintPass for TypeLimits {
306306

307307
fn uint_ty_range(uint_ty: ast::UintTy) -> (u64, u64) {
308308
match uint_ty {
309-
ast::TyU => (u64::MIN, u64::MAX),
309+
ast::TyUs=> (u64::MIN, u64::MAX),
310310
ast::TyU8 => (u8::MIN as u64, u8::MAX as u64),
311311
ast::TyU16 => (u16::MIN as u64, u16::MAX as u64),
312312
ast::TyU32 => (u32::MIN as u64, u32::MAX as u64),
@@ -323,7 +323,7 @@ impl LintPass for TypeLimits {
323323

324324
fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
325325
match int_ty {
326-
ast::TyI => int_ty_bits(target_int_ty, target_int_ty),
326+
ast::TyIs=> int_ty_bits(target_int_ty, target_int_ty),
327327
ast::TyI8 => i8::BITS as u64,
328328
ast::TyI16 => i16::BITS as u64,
329329
ast::TyI32 => i32::BITS as u64,
@@ -333,7 +333,7 @@ impl LintPass for TypeLimits {
333333

334334
fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
335335
match uint_ty {
336-
ast::TyU => uint_ty_bits(target_uint_ty, target_uint_ty),
336+
ast::TyUs=> uint_ty_bits(target_uint_ty, target_uint_ty),
337337
ast::TyU8 => u8::BITS as u64,
338338
ast::TyU16 => u16::BITS as u64,
339339
ast::TyU32 => u32::BITS as u64,
@@ -404,14 +404,14 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
404404
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
405405
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
406406
match self.cx.tcx.def_map.borrow()[path_id].clone() {
407-
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
407+
def::DefPrimTy(ast::TyInt(ast::TyIs)) => {
408408
self.cx.span_lint(IMPROPER_CTYPES, sp,
409-
"found rust type `int` in foreign module, while \
409+
"found rust type `isize` in foreign module, while \
410410
libc::c_int or libc::c_long should be used");
411411
}
412-
def::DefPrimTy(ast::TyUint(ast::TyU)) => {
412+
def::DefPrimTy(ast::TyUint(ast::TyUs)) => {
413413
self.cx.span_lint(IMPROPER_CTYPES, sp,
414-
"found rust type `uint` in foreign module, while \
414+
"found rust type `usize` in foreign module, while \
415415
libc::c_uint or libc::c_ulong should be used");
416416
}
417417
def::DefTy(..) => {

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
443443
let tcx = st.tcx;
444444
match next(st) {
445445
'b' => return tcx.types.bool,
446-
'i' => return tcx.types.int,
447-
'u' => return tcx.types.uint,
446+
'i' => { /* eat the s of is */ next(st); return tcx.types.int },
447+
'u' => { /* eat the s of us */ next(st); return tcx.types.uint },
448448
'M' => {
449449
match next(st) {
450450
'b' => return tcx.types.u8,

src/librustc/metadata/tyencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
6161
ty::ty_char => mywrite!(w, "c"),
6262
ty::ty_int(t) => {
6363
match t {
64-
ast::TyI => mywrite!(w, "i"),
64+
ast::TyIs => mywrite!(w, "is"),
6565
ast::TyI8 => mywrite!(w, "MB"),
6666
ast::TyI16 => mywrite!(w, "MW"),
6767
ast::TyI32 => mywrite!(w, "ML"),
@@ -70,7 +70,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
7070
}
7171
ty::ty_uint(t) => {
7272
match t {
73-
ast::TyU => mywrite!(w, "u"),
73+
ast::TyUs => mywrite!(w, "us"),
7474
ast::TyU8 => mywrite!(w, "Mb"),
7575
ast::TyU16 => mywrite!(w, "Mw"),
7676
ast::TyU32 => mywrite!(w, "Ml"),

src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
528528

529529
eval_const_expr_partial(tcx, &**base)
530530
.and_then(|val| define_casts!(val, {
531-
ty::ty_int(ast::TyI) => (int, const_int, i64),
531+
ty::ty_int(ast::TyIs) => (int, const_int, i64),
532532
ty::ty_int(ast::TyI8) => (i8, const_int, i64),
533533
ty::ty_int(ast::TyI16) => (i16, const_int, i64),
534534
ty::ty_int(ast::TyI32) => (i32, const_int, i64),
535535
ty::ty_int(ast::TyI64) => (i64, const_int, i64),
536-
ty::ty_uint(ast::TyU) => (uint, const_uint, u64),
536+
ty::ty_uint(ast::TyUs) => (uint, const_uint, u64),
537537
ty::ty_uint(ast::TyU8) => (u8, const_uint, u64),
538538
ty::ty_uint(ast::TyU16) => (u16, const_uint, u64),
539539
ty::ty_uint(ast::TyU32) => (u32, const_uint, u64),

src/librustc/middle/ty.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,12 +2302,12 @@ impl<'tcx> CommonTypes<'tcx> {
23022302
bool: intern_ty(arena, interner, ty_bool),
23032303
char: intern_ty(arena, interner, ty_char),
23042304
err: intern_ty(arena, interner, ty_err),
2305-
int: intern_ty(arena, interner, ty_int(ast::TyI)),
2305+
int: intern_ty(arena, interner, ty_int(ast::TyIs)),
23062306
i8: intern_ty(arena, interner, ty_int(ast::TyI8)),
23072307
i16: intern_ty(arena, interner, ty_int(ast::TyI16)),
23082308
i32: intern_ty(arena, interner, ty_int(ast::TyI32)),
23092309
i64: intern_ty(arena, interner, ty_int(ast::TyI64)),
2310-
uint: intern_ty(arena, interner, ty_uint(ast::TyU)),
2310+
uint: intern_ty(arena, interner, ty_uint(ast::TyUs)),
23112311
u8: intern_ty(arena, interner, ty_uint(ast::TyU8)),
23122312
u16: intern_ty(arena, interner, ty_uint(ast::TyU16)),
23132313
u32: intern_ty(arena, interner, ty_uint(ast::TyU32)),
@@ -2653,7 +2653,7 @@ impl FlagComputation {
26532653

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

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

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

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

38973897
pub fn type_is_uint(ty: Ty) -> bool {
38983898
match ty.sty {
3899-
ty_infer(IntVar(_)) | ty_uint(ast::TyU) => true,
3899+
ty_infer(IntVar(_)) | ty_uint(ast::TyUs) => true,
39003900
_ => false
39013901
}
39023902
}
@@ -3942,7 +3942,7 @@ pub fn type_is_signed(ty: Ty) -> bool {
39423942

39433943
pub fn type_is_machine(ty: Ty) -> bool {
39443944
match ty.sty {
3945-
ty_int(ast::TyI) | ty_uint(ast::TyU) => false,
3945+
ty_int(ast::TyIs) | ty_uint(ast::TyUs) => false,
39463946
ty_int(..) | ty_uint(..) | ty_float(..) => true,
39473947
_ => false
39483948
}

src/librustc_resolve/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ use syntax::ast::{PolyTraitRef, PrimTy, SelfExplicit};
8686
use syntax::ast::{RegionTyParamBound, StructField};
8787
use syntax::ast::{TraitRef, TraitTyParamBound};
8888
use syntax::ast::{Ty, TyBool, TyChar, TyF32};
89-
use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt, TyObjectSum};
89+
use syntax::ast::{TyF64, TyFloat, TyIs, TyI8, TyI16, TyI32, TyI64, TyInt, TyObjectSum};
9090
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyPolyTraitRef, TyQPath};
91-
use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint};
91+
use syntax::ast::{TyRptr, TyStr, TyUs, TyU8, TyU16, TyU32, TyU64, TyUint};
9292
use syntax::ast::{TypeImplItem};
9393
use syntax::ast;
9494
use syntax::ast_map;
@@ -833,13 +833,15 @@ impl PrimitiveTypeTable {
833833
table.intern("char", TyChar);
834834
table.intern("f32", TyFloat(TyF32));
835835
table.intern("f64", TyFloat(TyF64));
836-
table.intern("int", TyInt(TyI));
836+
table.intern("int", TyInt(TyIs));
837+
table.intern("isize", TyInt(TyIs));
837838
table.intern("i8", TyInt(TyI8));
838839
table.intern("i16", TyInt(TyI16));
839840
table.intern("i32", TyInt(TyI32));
840841
table.intern("i64", TyInt(TyI64));
841842
table.intern("str", TyStr);
842-
table.intern("uint", TyUint(TyU));
843+
table.intern("uint", TyUint(TyUs));
844+
table.intern("usize", TyUint(TyUs));
843845
table.intern("u8", TyUint(TyU8));
844846
table.intern("u16", TyUint(TyU16));
845847
table.intern("u32", TyUint(TyU32));

src/librustc_trans/trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
903903
ty::ty_int(t) => {
904904
let llty = Type::int_from_ty(cx.ccx(), t);
905905
let min = match t {
906-
ast::TyI if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
907-
ast::TyI => i64::MIN as u64,
906+
ast::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
907+
ast::TyIs => i64::MIN as u64,
908908
ast::TyI8 => i8::MIN as u64,
909909
ast::TyI16 => i16::MIN as u64,
910910
ast::TyI32 => i32::MIN as u64,

src/librustc_trans/trans/debuginfo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,14 +1797,14 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
17971797
ty::ty_bool => ("bool".to_string(), DW_ATE_boolean),
17981798
ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char),
17991799
ty::ty_int(int_ty) => match int_ty {
1800-
ast::TyI => ("int".to_string(), DW_ATE_signed),
1800+
ast::TyIs => ("isize".to_string(), DW_ATE_signed),
18011801
ast::TyI8 => ("i8".to_string(), DW_ATE_signed),
18021802
ast::TyI16 => ("i16".to_string(), DW_ATE_signed),
18031803
ast::TyI32 => ("i32".to_string(), DW_ATE_signed),
18041804
ast::TyI64 => ("i64".to_string(), DW_ATE_signed)
18051805
},
18061806
ty::ty_uint(uint_ty) => match uint_ty {
1807-
ast::TyU => ("uint".to_string(), DW_ATE_unsigned),
1807+
ast::TyUs => ("usize".to_string(), DW_ATE_unsigned),
18081808
ast::TyU8 => ("u8".to_string(), DW_ATE_unsigned),
18091809
ast::TyU16 => ("u16".to_string(), DW_ATE_unsigned),
18101810
ast::TyU32 => ("u32".to_string(), DW_ATE_unsigned),
@@ -3729,12 +3729,12 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
37293729
ty::ty_bool => output.push_str("bool"),
37303730
ty::ty_char => output.push_str("char"),
37313731
ty::ty_str => output.push_str("str"),
3732-
ty::ty_int(ast::TyI) => output.push_str("int"),
3732+
ty::ty_int(ast::TyIs) => output.push_str("isize"),
37333733
ty::ty_int(ast::TyI8) => output.push_str("i8"),
37343734
ty::ty_int(ast::TyI16) => output.push_str("i16"),
37353735
ty::ty_int(ast::TyI32) => output.push_str("i32"),
37363736
ty::ty_int(ast::TyI64) => output.push_str("i64"),
3737-
ty::ty_uint(ast::TyU) => output.push_str("uint"),
3737+
ty::ty_uint(ast::TyUs) => output.push_str("usize"),
37383738
ty::ty_uint(ast::TyU8) => output.push_str("u8"),
37393739
ty::ty_uint(ast::TyU16) => output.push_str("u16"),
37403740
ty::ty_uint(ast::TyU32) => output.push_str("u32"),

src/librustc_trans/trans/type_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Type {
112112

113113
pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
114114
match t {
115-
ast::TyI => ccx.int_type(),
115+
ast::TyIs => ccx.int_type(),
116116
ast::TyI8 => Type::i8(ccx),
117117
ast::TyI16 => Type::i16(ccx),
118118
ast::TyI32 => Type::i32(ccx),
@@ -122,7 +122,7 @@ impl Type {
122122

123123
pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
124124
match t {
125-
ast::TyU => ccx.int_type(),
125+
ast::TyUs => ccx.int_type(),
126126
ast::TyU8 => Type::i8(ccx),
127127
ast::TyU16 => Type::i16(ccx),
128128
ast::TyU32 => Type::i32(ccx),

src/librustc_trans/trans/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type {
264264
}
265265

266266
match unsized_part_of_type(cx.tcx(), t).sty {
267-
ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyU),
267+
ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyUs),
268268
ty::ty_trait(_) => Type::vtable_ptr(cx),
269269
_ => panic!("Unexpected type returned from unsized_part_of_type : {}",
270270
t.repr(cx.tcx()))

0 commit comments

Comments
 (0)