auto merge of #13257 : alexcrichton/rust/index-uint, r=pnkfelix
The details are outlined in the first commit. Closes #10453
This commit is contained in:
commit
f503f6c0b9
src
libcollections
libnative/io
librand
librustc/middle
librustuv
libserialize
libstd
libsyntax/parse
libterm/terminfo
test
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
};
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<t> {
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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::*;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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::*;
|
||||
|
@ -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) {
|
||||
|
@ -411,23 +411,23 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+
|
||||
// If reached left end of number, have to
|
||||
// insert additional digit:
|
||||
if i < 0
|
||||
|| buf[i] == '-' as u8
|
||||
|| buf[i] == '+' as u8 {
|
||||
|| buf[i as uint] == '-' as u8
|
||||
|| buf[i as uint] == '+' as u8 {
|
||||
buf.insert((i + 1) as uint, value2ascii(1));
|
||||
break;
|
||||
}
|
||||
|
||||
// Skip the '.'
|
||||
if buf[i] == '.' as u8 { i -= 1; continue; }
|
||||
if buf[i as uint] == '.' as u8 { i -= 1; continue; }
|
||||
|
||||
// Either increment the digit,
|
||||
// or set to 0 if max and carry the 1.
|
||||
let current_digit = ascii2value(buf[i]);
|
||||
let current_digit = ascii2value(buf[i as uint]);
|
||||
if current_digit < (radix - 1) {
|
||||
buf[i] = value2ascii(current_digit+1);
|
||||
buf[i as uint] = value2ascii(current_digit+1);
|
||||
break;
|
||||
} else {
|
||||
buf[i] = value2ascii(0);
|
||||
buf[i as uint] = value2ascii(0);
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -2922,8 +2922,6 @@ mod tests {
|
||||
|
||||
fn square(n: uint) -> 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;
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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<Vec<u8> ,~str> {
|
||||
mod test {
|
||||
use super::{expand,String,Variables,Number};
|
||||
use std::result::Ok;
|
||||
use std::vec;
|
||||
|
||||
#[test]
|
||||
fn test_basic_setabf() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
25
src/test/compile-fail/indexing-requires-a-uint.rs
Normal file
25
src/test/compile-fail/indexing-requires-a-uint.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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>(_: 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::<int>(i); // i should not be re-coerced back to an int
|
||||
//~^ ERROR: mismatched types
|
||||
}
|
||||
|
26
src/test/compile-fail/integral-indexing.rs
Normal file
26
src/test/compile-fail/integral-indexing.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
let v: Vec<int> = 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
|
||||
}
|
@ -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();
|
||||
|
@ -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::<int, &[int]>(z), z.len());
|
||||
}
|
||||
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<int> = 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]);
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user