Skip to content

Commit

Permalink
auto merge of #13257 : alexcrichton/rust/index-uint, r=pnkfelix
Browse files Browse the repository at this point in the history
The details are outlined in the first commit. 

Closes #10453
  • Loading branch information
bors committed Apr 2, 2014
2 parents 3786b55 + 9a259f4 commit f503f6c
Show file tree
Hide file tree
Showing 31 changed files with 165 additions and 119 deletions.
18 changes: 9 additions & 9 deletions src/libcollections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,12 +1600,12 @@ mod test_map {

#[deriving(Hash, Eq, TotalEq)]
struct Dropable {
k: int
k: uint
}


impl Dropable {
fn new(k: int) -> Dropable {
fn new(k: uint) -> Dropable {
local_data::get_mut(drop_vector,
|v| { v.unwrap().as_mut_slice()[k] += 1; });

Expand All @@ -1628,24 +1628,24 @@ mod test_map {
let mut m = HashMap::new();

local_data::get(drop_vector, |v| {
for i in range(0, 200) {
for i in range(0u, 200) {
assert_eq!(v.unwrap().as_slice()[i], 0);
}
});

for i in range(0, 100) {
for i in range(0u, 100) {
let d1 = Dropable::new(i);
let d2 = Dropable::new(i+100);
m.insert(d1, d2);
}

local_data::get(drop_vector, |v| {
for i in range(0, 200) {
for i in range(0u, 200) {
assert_eq!(v.unwrap().as_slice()[i], 1);
}
});

for i in range(0, 50) {
for i in range(0u, 50) {
let k = Dropable::new(i);
let v = m.pop(&k);

Expand All @@ -1658,20 +1658,20 @@ mod test_map {
}

local_data::get(drop_vector, |v| {
for i in range(0, 50) {
for i in range(0u, 50) {
assert_eq!(v.unwrap().as_slice()[i], 0);
assert_eq!(v.unwrap().as_slice()[i+100], 0);
}

for i in range(50, 100) {
for i in range(50u, 100) {
assert_eq!(v.unwrap().as_slice()[i], 1);
assert_eq!(v.unwrap().as_slice()[i+100], 1);
}
});
}

local_data::get(drop_vector, |v| {
for i in range(0, 200) {
for i in range(0u, 200) {
assert_eq!(v.unwrap().as_slice()[i], 0);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/timer_other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ mod imp {
}

pub fn fd_set(set: &mut fd_set, fd: i32) {
set.fds_bits[fd / 32] |= 1 << (fd % 32);
set.fds_bits[(fd / 32) as uint] |= 1 << (fd % 32);
}

extern {
Expand All @@ -323,7 +323,7 @@ mod imp {
}

pub fn fd_set(set: &mut fd_set, fd: i32) {
set.fds_bits[fd / 64] |= (1 << (fd % 64)) as u64;
set.fds_bits[(fd / 64) as uint] |= (1 << (fd % 64)) as u64;
}

extern {
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/timer_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
}
} else {
let remove = {
match &chans[idx - 1] {
match &chans[idx as uint - 1] {
&(ref c, oneshot) => !c.try_send(()) || oneshot
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl IsaacRng {
if use_rsl {
macro_rules! memloop (
($arr:expr) => {{
for i in range_step(0u32, RAND_SIZE, 8) {
for i in range_step(0, RAND_SIZE as uint, 8) {
a+=$arr[i ]; b+=$arr[i+1];
c+=$arr[i+2]; d+=$arr[i+3];
e+=$arr[i+4]; f+=$arr[i+5];
Expand All @@ -120,7 +120,7 @@ impl IsaacRng {
memloop!(self.rsl);
memloop!(self.mem);
} else {
for i in range_step(0u32, RAND_SIZE, 8) {
for i in range_step(0, RAND_SIZE as uint, 8) {
mix!();
self.mem[i ]=a; self.mem[i+1]=b;
self.mem[i+2]=c; self.mem[i+3]=d;
Expand All @@ -143,7 +143,7 @@ impl IsaacRng {
static MIDPOINT: uint = RAND_SIZE as uint / 2;

macro_rules! ind (($x:expr) => {
self.mem[($x >> 2) & (RAND_SIZE - 1)]
self.mem[(($x >> 2) & (RAND_SIZE - 1)) as uint]
});
macro_rules! rngstep(
($j:expr, $shift:expr) => {{
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Rng for IsaacRng {
self.isaac();
}
self.cnt -= 1;
self.rsl[self.cnt]
self.rsl[self.cnt as uint]
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,13 @@ pub fn type_is_integral(ty: t) -> bool {
}
}

pub fn type_is_uint(ty: t) -> bool {
match get(ty).sty {
ty_infer(IntVar(_)) | ty_uint(ast::TyU) => true,
_ => false
}
}

pub fn type_is_char(ty: t) -> bool {
match get(ty).sty {
ty_char => true,
Expand Down Expand Up @@ -4358,7 +4365,7 @@ pub fn is_binopable(cx: &ctxt, ty: t, op: ast::BinOp) -> bool {
/*bot*/ [t, t, t, t, t, t, t, t],
/*raw ptr*/ [f, f, f, f, t, t, f, f]];

return tbl[tycat(cx, ty)][opcat(op)];
return tbl[tycat(cx, ty) as uint ][opcat(op) as uint];
}

pub fn ty_params_to_tys(tcx: &ctxt, generics: &ast::Generics) -> Vec<t> {
Expand Down
16 changes: 15 additions & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
lvalue_pref, |base_t, _| ty::index(base_t));
match field_ty {
Some(mt) => {
require_integral(fcx, idx.span, idx_t);
check_expr_has_type(fcx, idx, ty::mk_uint());
fcx.write_ty(id, mt.ty);
fcx.write_autoderef_adjustment(base.id, autoderefs);
}
Expand Down Expand Up @@ -3195,6 +3195,15 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
unifier();
}
pub fn require_uint(fcx: &FnCtxt, sp: Span, t: ty::t) {
if !type_is_uint(fcx, sp, t) {
fcx.type_error_message(sp, |actual| {
format!("mismatched types: expected `uint` type but found `{}`",
actual)
}, t, None);
}
}

pub fn require_integral(fcx: &FnCtxt, sp: Span, t: ty::t) {
if !type_is_integral(fcx, sp, t) {
fcx.type_error_message(sp, |actual| {
Expand Down Expand Up @@ -3854,6 +3863,11 @@ pub fn type_is_integral(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
return ty::type_is_integral(typ_s);
}

pub fn type_is_uint(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_uint(typ_s);
}

pub fn type_is_scalar(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_scalar(typ_s);
Expand Down
8 changes: 4 additions & 4 deletions src/librustuv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ mod test {
Ok(10) => {} e => fail!("{:?}", e),
}
for i in range(0, 10u8) {
assert_eq!(buf[i], i + 1);
assert_eq!(buf[i as uint], i + 1);
}
}
Err(e) => fail!("{:?}", e)
Expand Down Expand Up @@ -827,7 +827,7 @@ mod test {
Ok(10) => {} e => fail!("{:?}", e),
}
for i in range(0, 10u8) {
assert_eq!(buf[i], i + 1);
assert_eq!(buf[i as uint], i + 1);
}
}
Err(e) => fail!("{:?}", e)
Expand Down Expand Up @@ -859,7 +859,7 @@ mod test {
e => fail!("{:?}", e),
}
for i in range(0, 10u8) {
assert_eq!(buf[i], i + 1);
assert_eq!(buf[i as uint], i + 1);
}
}
Err(e) => fail!("{:?}", e)
Expand Down Expand Up @@ -891,7 +891,7 @@ mod test {
e => fail!("{:?}", e),
}
for i in range(0, 10u8) {
assert_eq!(buf[i], i + 1);
assert_eq!(buf[i as uint], i + 1);
}
}
Err(e) => fail!("{:?}", e)
Expand Down
18 changes: 9 additions & 9 deletions src/libserialize/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ impl<'a> ToBase64 for &'a [u8] {
(self[i + 2] as u32);

// This 24-bit number gets separated into four 6-bit numbers.
v.push(bytes[(n >> 18) & 63]);
v.push(bytes[(n >> 12) & 63]);
v.push(bytes[(n >> 6 ) & 63]);
v.push(bytes[n & 63]);
v.push(bytes[((n >> 18) & 63) as uint]);
v.push(bytes[((n >> 12) & 63) as uint]);
v.push(bytes[((n >> 6 ) & 63) as uint]);
v.push(bytes[(n & 63) as uint]);

cur_length += 4;
i += 3;
Expand All @@ -125,8 +125,8 @@ impl<'a> ToBase64 for &'a [u8] {
0 => (),
1 => {
let n = (self[i] as u32) << 16;
v.push(bytes[(n >> 18) & 63]);
v.push(bytes[(n >> 12) & 63]);
v.push(bytes[((n >> 18) & 63) as uint]);
v.push(bytes[((n >> 12) & 63) as uint]);
if config.pad {
v.push('=' as u8);
v.push('=' as u8);
Expand All @@ -135,9 +135,9 @@ impl<'a> ToBase64 for &'a [u8] {
2 => {
let n = (self[i] as u32) << 16 |
(self[i + 1u] as u32) << 8;
v.push(bytes[(n >> 18) & 63]);
v.push(bytes[(n >> 12) & 63]);
v.push(bytes[(n >> 6 ) & 63]);
v.push(bytes[((n >> 18) & 63) as uint]);
v.push(bytes[((n >> 12) & 63) as uint]);
v.push(bytes[((n >> 6 ) & 63) as uint]);
if config.pad {
v.push('=' as u8);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libserialize/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl<'a> ToHex for &'a [u8] {
fn to_hex(&self) -> ~str {
let mut v = slice::with_capacity(self.len() * 2);
for &byte in self.iter() {
v.push(CHARS[byte >> 4]);
v.push(CHARS[byte & 0xf]);
v.push(CHARS[(byte >> 4) as uint]);
v.push(CHARS[(byte & 0xf) as uint]);
}

unsafe {
Expand Down
18 changes: 11 additions & 7 deletions src/libstd/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ impl Ascii {
/// Convert to lowercase.
#[inline]
pub fn to_lower(self) -> Ascii {
Ascii{chr: ASCII_LOWER_MAP[self.chr]}
Ascii{chr: ASCII_LOWER_MAP[self.chr as uint]}
}

/// Convert to uppercase.
#[inline]
pub fn to_upper(self) -> Ascii {
Ascii{chr: ASCII_UPPER_MAP[self.chr]}
Ascii{chr: ASCII_UPPER_MAP[self.chr as uint]}
}

/// Compares two ascii characters of equality, ignoring case.
#[inline]
pub fn eq_ignore_case(self, other: Ascii) -> bool {
ASCII_LOWER_MAP[self.chr] == ASCII_LOWER_MAP[other.chr]
ASCII_LOWER_MAP[self.chr as uint] == ASCII_LOWER_MAP[other.chr as uint]
}

// the following methods are like ctype, and the implementation is inspired by musl
Expand Down Expand Up @@ -370,8 +370,12 @@ impl<'a> StrAsciiExt for &'a str {

#[inline]
fn eq_ignore_ascii_case(&self, other: &str) -> bool {
self.len() == other.len() && self.as_bytes().iter().zip(other.as_bytes().iter()).all(
|(byte_self, byte_other)| ASCII_LOWER_MAP[*byte_self] == ASCII_LOWER_MAP[*byte_other])
self.len() == other.len() &&
self.as_bytes().iter().zip(other.as_bytes().iter()).all(
|(byte_self, byte_other)| {
ASCII_LOWER_MAP[*byte_self as uint] ==
ASCII_LOWER_MAP[*byte_other as uint]
})
}
}

Expand All @@ -392,15 +396,15 @@ unsafe fn str_map_bytes(string: ~str, map: &'static [u8]) -> ~str {
let mut bytes = string.into_bytes();

for b in bytes.mut_iter() {
*b = map[*b];
*b = map[*b as uint];
}

str::raw::from_utf8_owned(bytes)
}

#[inline]
unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> ~str {
let bytes = string.bytes().map(|b| map[b]).collect::<~[_]>();
let bytes = string.bytes().map(|b| map[b as uint]).collect::<~[_]>();

str::raw::from_utf8_owned(bytes)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/comm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub use comm::select::{Select, Handle};
macro_rules! test (
{ fn $name:ident() $b:block $(#[$a:meta])*} => (
mod $name {
#[allow(unused_imports)];
#![allow(unused_imports)]

use native;
use comm::*;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {
assert!(f == i && f == v);

buf.push(t as u8);
state_inc.write_u8(t);
state_inc.write_u8(t as u8);

t += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
macro_rules! iotest (
{ fn $name:ident() $b:block $(#[$a:meta])* } => (
mod $name {
#[allow(unused_imports)];
#![allow(unused_imports)]

use super::super::*;
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ mod tests {
macro_rules! test_next_power_of_two(
($test_name:ident, $T:ident) => (
fn $test_name() {
#[test];
#![test]
assert_eq!(next_power_of_two::<$T>(0), 0);
let mut next_power = 1;
for i in range::<$T>(1, 40) {
Expand All @@ -1675,7 +1675,7 @@ mod tests {
macro_rules! test_checked_next_power_of_two(
($test_name:ident, $T:ident) => (
fn $test_name() {
#[test];
#![test]
assert_eq!(checked_next_power_of_two::<$T>(0), None);
let mut next_power = 1;
for i in range::<$T>(1, 40) {
Expand Down
Loading

0 comments on commit f503f6c

Please sign in to comment.