diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs index 47100559f449..7a51fca6cd5e 100644 --- a/src/libcollections/hashmap.rs +++ b/src/libcollections/hashmap.rs @@ -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; }); @@ -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); @@ -1658,12 +1658,12 @@ 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); } @@ -1671,7 +1671,7 @@ mod test_map { } 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); } }); diff --git a/src/libnative/io/timer_other.rs b/src/libnative/io/timer_other.rs index ea237944bad9..7979075aa025 100644 --- a/src/libnative/io/timer_other.rs +++ b/src/libnative/io/timer_other.rs @@ -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 { @@ -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 { diff --git a/src/libnative/io/timer_win32.rs b/src/libnative/io/timer_win32.rs index a342afa68547..3e420e454488 100644 --- a/src/libnative/io/timer_win32.rs +++ b/src/libnative/io/timer_win32.rs @@ -78,7 +78,7 @@ fn helper(input: libc::HANDLE, messages: Receiver) { } } else { let remove = { - match &chans[idx - 1] { + match &chans[idx as uint - 1] { &(ref c, oneshot) => !c.try_send(()) || oneshot } }; diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 23371ed2bd8b..1d9da40f18b6 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -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]; @@ -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; @@ -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) => {{ @@ -188,7 +188,7 @@ impl Rng for IsaacRng { self.isaac(); } self.cnt -= 1; - self.rsl[self.cnt] + self.rsl[self.cnt as uint] } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 8a616496f064..176ed409dd49 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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, @@ -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 { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 9aa98ee5f8e8..4cf3cc51cc1b 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -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); } @@ -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| { @@ -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); diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 0514975cc7b2..a6d1e1a6efdb 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 62e078e26c1c..6aad2f5abbf5 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -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; @@ -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); @@ -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); } diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index a95c77c7c131..e6658f3b3670 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -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 { diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index c9112caa1b96..a52658da209c 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -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 @@ -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] + }) } } @@ -392,7 +396,7 @@ 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) @@ -400,7 +404,7 @@ unsafe fn str_map_bytes(string: ~str, map: &'static [u8]) -> ~str { #[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) } diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index e951077ac832..d01c4913b32a 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -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::*; diff --git a/src/libstd/hash/sip.rs b/src/libstd/hash/sip.rs index d780c30d8508..6217ff0f58c7 100644 --- a/src/libstd/hash/sip.rs +++ b/src/libstd/hash/sip.rs @@ -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; } diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index d5bd7ad24f89..14b9b5c1e061 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -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::*; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 2c628112957a..761bd072bf8d 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -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) { @@ -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) { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 15c7b251fa74..b15b5872fc28 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -411,23 +411,23 @@ pub fn float_to_str_bytes_common uint { n * n } - fn square_ref(n: &uint) -> uint { square(*n) } - fn is_odd(n: &uint) -> bool { *n % 2u == 1u } #[test] @@ -4441,7 +4439,7 @@ mod bench { unsafe { v.set_len(1024); } - for i in range(0, 1024) { + for i in range(0u, 1024) { v[i] = 0; } }); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 408d236ccc6e..1d80af70b975 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1053,7 +1053,7 @@ static UTF8_CHAR_WIDTH: [u8, ..256] = [ /// Given a first byte, determine how many bytes are in this UTF-8 character #[inline] pub fn utf8_char_width(b: u8) -> uint { - return UTF8_CHAR_WIDTH[b] as uint; + return UTF8_CHAR_WIDTH[b as uint] as uint; } /// Struct that contains a `char` and the index of the first byte of @@ -2636,7 +2636,7 @@ impl<'a> StrSlice<'a> for &'a str { // Multibyte case is a fn to allow char_range_at to inline cleanly fn multibyte_char_range_at(s: &str, i: uint) -> CharRange { let mut val = s[i] as u32; - let w = UTF8_CHAR_WIDTH[val] as uint; + let w = UTF8_CHAR_WIDTH[val as uint] as uint; assert!((w != 0)); val = utf8_first_byte!(val, w); @@ -2665,7 +2665,7 @@ impl<'a> StrSlice<'a> for &'a str { } let mut val = s[i] as u32; - let w = UTF8_CHAR_WIDTH[val] as uint; + let w = UTF8_CHAR_WIDTH[val as uint] as uint; assert!((w != 0)); val = utf8_first_byte!(val, w); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 83cc92d48284..b3e488a464d9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -780,10 +780,10 @@ impl<'a> Parser<'a> { -> R { let dist = distance as int; while self.buffer_length() < dist { - self.buffer[self.buffer_end] = self.reader.next_token(); + self.buffer[self.buffer_end as uint] = self.reader.next_token(); self.buffer_end = (self.buffer_end + 1) & 3; } - f(&self.buffer[(self.buffer_start + dist - 1) & 3].tok) + f(&self.buffer[((self.buffer_start + dist - 1) & 3) as uint].tok) } pub fn fatal(&mut self, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(self.span, m) diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index aed752fcb094..408d452adba2 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -293,12 +293,12 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) if cur >= 'A' && cur <= 'Z' { if stack.len() > 0 { let idx = (cur as u8) - ('A' as u8); - vars.sta[idx] = stack.pop().unwrap(); + vars.sta[idx as uint] = stack.pop().unwrap(); } else { return Err(~"stack is empty") } } else if cur >= 'a' && cur <= 'z' { if stack.len() > 0 { let idx = (cur as u8) - ('a' as u8); - vars.dyn[idx] = stack.pop().unwrap(); + vars.dyn[idx as uint] = stack.pop().unwrap(); } else { return Err(~"stack is empty") } } else { return Err(~"bad variable name in %P"); @@ -307,10 +307,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) GetVar => { if cur >= 'A' && cur <= 'Z' { let idx = (cur as u8) - ('A' as u8); - stack.push(vars.sta[idx].clone()); + stack.push(vars.sta[idx as uint].clone()); } else if cur >= 'a' && cur <= 'z' { let idx = (cur as u8) - ('a' as u8); - stack.push(vars.dyn[idx].clone()); + stack.push(vars.dyn[idx as uint].clone()); } else { return Err(~"bad variable name in %g"); } @@ -563,7 +563,6 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,~str> { mod test { use super::{expand,String,Variables,Number}; use std::result::Ok; - use std::vec; #[test] fn test_basic_setabf() { diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index edaa55a66031..6d87d91ffc02 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -223,7 +223,7 @@ pub fn parse(file: &mut io::Reader, if b < 0 { return Err(~"error: expected more bools but hit EOF"); } else if b == 1 { - bools_map.insert(bnames[i].to_owned(), true); + bools_map.insert(bnames[i as uint].to_owned(), true); } } } @@ -237,7 +237,7 @@ pub fn parse(file: &mut io::Reader, for i in range(0, numbers_count) { let n = try!(file.read_le_u16()); if n != 0xFFFF { - numbers_map.insert(nnames[i].to_owned(), n); + numbers_map.insert(nnames[i as uint].to_owned(), n); } } } diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index babf3f737fbe..7e41fdea778d 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -58,8 +58,9 @@ impl Noise2DContext { } fn get_gradient(&self, x: i32, y: i32) -> Vec2 { - let idx = self.permutations[x & 255] + self.permutations[y & 255]; - self.rgradients[idx & 255] + let idx = self.permutations[(x & 255) as uint] + + self.permutations[(y & 255) as uint]; + self.rgradients[(idx & 255) as uint] } fn get_gradients(&self, x: f32, y: f32) -> ([Vec2, ..4], [Vec2, ..4]) { @@ -103,16 +104,16 @@ fn main() { let n2d = Noise2DContext::new(); for _ in range(0, 100) { - for y in range(0, 256) { - for x in range(0, 256) { + for y in range(0u, 256) { + for x in range(0u, 256) { let v = n2d.get(x as f32 * 0.1, y as f32 * 0.1); pixels[y*256+x] = v * 0.5 + 0.5; } } } - for y in range(0, 256) { - for x in range(0, 256) { + for y in range(0u, 256) { + for x in range(0u, 256) { let idx = (pixels[y*256+x] / 0.2) as uint; print!("{:c}", symbols[idx]); } diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 8d860206d0cd..e650367c6f56 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -30,7 +30,7 @@ fn fannkuch_redux(n: i32) -> i32 { let mut r = n; loop { while r != 1 { - count[r - 1] = r; + count[r as uint - 1] = r; r -= 1; } @@ -71,13 +71,13 @@ fn fannkuch_redux(n: i32) -> i32 { let mut i: i32 = 0; while i < r { let j = i + 1; - perm1[i] = perm1[j]; + perm1[i as uint] = perm1[j as uint]; i = j; } - perm1[r] = perm0; + perm1[r as uint] = perm0; - count[r] -= 1; - if count[r] > 0 { + count[r as uint] -= 1; + if count[r as uint] > 0 { break; } r += 1; diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 71d900ba03ac..7ceaaa7ad22e 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -201,7 +201,7 @@ fn pack_symbol(c: u8) -> u8 { } fn unpack_symbol(c: u8) -> u8 { - TABLE[c] + TABLE[c as uint] } fn generate_frequencies(frequencies: &mut Table, diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index b26053bdf353..45ce17766209 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -255,9 +255,9 @@ fn search( // for every unused piece for id in range(0, 10).filter(|id| board & (1 << (id + 50)) == 0) { // for each mask that fits on the board - for &m in masks[id].get(i as uint) - .iter() - .filter(|&m| board & *m == 0) { + for &m in masks[id as uint].get(i as uint) + .iter() + .filter(|&m| board & *m == 0) { // This check is too costy. //if is_board_unfeasible(board | m, masks) {continue;} if !search(masks, board | m, i + 1, Cons(m, &cur), data) { diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index acd6620d4afd..a96e9e9f81a0 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -29,8 +29,8 @@ fn make_complements() -> [u8, ..256] { } let lower = 'A' as u8 - 'a' as u8; for &(from, to) in transforms.iter() { - complements[from as u8] = to as u8; - complements[from as u8 - lower] = to as u8; + complements[from as uint] = to as u8; + complements[(from as u8 - lower) as uint] = to as u8; } complements } @@ -70,11 +70,11 @@ fn main() { loop { match (it.next(), it.next_back()) { (Some(front), Some(back)) => { - let tmp = complements[*front]; - *front = complements[*back]; + let tmp = complements[*front as uint]; + *front = complements[*back as uint]; *back = tmp; } - (Some(last), None) => *last = complements[*last], // last element + (Some(last), None) => *last = complements[*last as uint], // last element _ => break // vector exhausted. } } diff --git a/src/test/compile-fail/indexing-requires-a-uint.rs b/src/test/compile-fail/indexing-requires-a-uint.rs new file mode 100644 index 000000000000..9ac4bd2566e8 --- /dev/null +++ b/src/test/compile-fail/indexing-requires-a-uint.rs @@ -0,0 +1,25 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Make sure that indexing an array is only valid with a `uint`, not any other +// integral type. + +fn main() { + fn bar(_: T) {} + [0][0u8]; //~ ERROR: mismatched types + + [0][0]; // should infer to be a uint + + let i = 0; // i is an IntVar + [0][i]; // i should be locked to uint + bar::(i); // i should not be re-coerced back to an int + //~^ ERROR: mismatched types +} + diff --git a/src/test/compile-fail/integral-indexing.rs b/src/test/compile-fail/integral-indexing.rs new file mode 100644 index 000000000000..feda4be87ac8 --- /dev/null +++ b/src/test/compile-fail/integral-indexing.rs @@ -0,0 +1,26 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn main() { + let v: Vec = vec!(0, 1, 2, 3, 4, 5); + let s: ~str = ~"abcdef"; + assert_eq!(v.as_slice()[3u], 3); + assert_eq!(v.as_slice()[3u8], 3); //~ ERROR: mismatched types + assert_eq!(v.as_slice()[3i8], 3); //~ ERROR: mismatched types + assert_eq!(v.as_slice()[3u32], 3); //~ ERROR: mismatched types + assert_eq!(v.as_slice()[3i32], 3); //~ ERROR: mismatched types + println!("{}", v.as_slice()[3u8]); //~ ERROR: mismatched types + assert_eq!(s[3u], 'd' as u8); + assert_eq!(s[3u8], 'd' as u8); //~ ERROR: mismatched types + assert_eq!(s[3i8], 'd' as u8); //~ ERROR: mismatched types + assert_eq!(s[3u32], 'd' as u8); //~ ERROR: mismatched types + assert_eq!(s[3i32], 'd' as u8); //~ ERROR: mismatched types + println!("{}", s[3u8]); //~ ERROR: mismatched types +} diff --git a/src/test/debug-info/lexical-scopes-in-block-expression.rs b/src/test/debug-info/lexical-scopes-in-block-expression.rs index 72611e3bafa7..2a3fbecad9dc 100644 --- a/src/test/debug-info/lexical-scopes-in-block-expression.rs +++ b/src/test/debug-info/lexical-scopes-in-block-expression.rs @@ -211,8 +211,8 @@ // check:$57 = 10 // debugger:continue -#[allow(unused_variable)]; -#[allow(dead_assignment)]; +#![allow(unused_variable)] +#![allow(dead_assignment)] static mut MUT_INT: int = 0; @@ -366,7 +366,7 @@ fn main() { zzz(); sentinel(); - val + val as uint }]; zzz(); diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 2682d9e54bc1..dddec5a56249 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -51,7 +51,7 @@ pub fn main() { // Now try it with a type that *needs* to be borrowed let z = [0,1,2,3]; // Call a method - z.iterate(|y| { assert!(z[*y] == *y); true }); + z.iterate(|y| { assert!(z[*y as uint] == *y); true }); // Call a parameterized function assert_eq!(length::(z), z.len()); } diff --git a/src/test/run-pass/integral-indexing.rs b/src/test/run-pass/integral-indexing.rs deleted file mode 100644 index b3885691093c..000000000000 --- a/src/test/run-pass/integral-indexing.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// This is a testcase for issue #94. -pub fn main() { - let v: Vec = vec!(0, 1, 2, 3, 4, 5); - let s: ~str = ~"abcdef"; - assert_eq!(v.as_slice()[3u], 3); - assert_eq!(v.as_slice()[3u8], 3); - assert_eq!(v.as_slice()[3i8], 3); - assert_eq!(v.as_slice()[3u32], 3); - assert_eq!(v.as_slice()[3i32], 3); - println!("{}", v.as_slice()[3u8]); - assert_eq!(s[3u], 'd' as u8); - assert_eq!(s[3u8], 'd' as u8); - assert_eq!(s[3i8], 'd' as u8); - assert_eq!(s[3u32], 'd' as u8); - assert_eq!(s[3i32], 'd' as u8); - println!("{}", s[3u8]); -} diff --git a/src/test/run-pass/utf8.rs b/src/test/run-pass/utf8.rs index 9531563fcbef..c7763617269e 100644 --- a/src/test/run-pass/utf8.rs +++ b/src/test/run-pass/utf8.rs @@ -44,7 +44,7 @@ pub fn main() { for ab in a.bytes() { println!("{}", i); println!("{}", ab); - let bb: u8 = b[i]; + let bb: u8 = b[i as uint]; println!("{}", bb); assert_eq!(ab, bb); i += 1;