1
Fork 0

Remove integer suffixes where the types in compiled code are identical.

This commit is contained in:
Eduard Burtescu 2015-03-03 10:42:26 +02:00 committed by Manish Goregaokar
parent 68740b4054
commit e64670888a
331 changed files with 1072 additions and 1074 deletions

View file

@ -42,7 +42,7 @@
//! } //! }
//! ``` //! ```
//! //!
//! This will print `Cons(1i32, Box(Cons(2i32, Box(Nil))))`. //! This will print `Cons(1, Box(Cons(2, Box(Nil))))`.
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]

View file

@ -72,13 +72,13 @@ fn test_show() {
#[test] #[test]
fn deref() { fn deref() {
fn homura<T: Deref<Target=i32>>(_: T) { } fn homura<T: Deref<Target=i32>>(_: T) { }
homura(Box::new(765i32)); homura(Box::new(765));
} }
#[test] #[test]
fn raw_sized() { fn raw_sized() {
unsafe { unsafe {
let x = Box::new(17i32); let x = Box::new(17);
let p = boxed::into_raw(x); let p = boxed::into_raw(x);
assert_eq!(17, *p); assert_eq!(17, *p);
*p = 19; *p = 19;

View file

@ -118,11 +118,11 @@ fn match_words <'a,'b>(a: &'a BitVec, b: &'b BitVec) -> (MatchWords<'a>, MatchWo
// have to uselessly pretend to pad the longer one for type matching // have to uselessly pretend to pad the longer one for type matching
if a_len < b_len { if a_len < b_len {
(a.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(b_len).skip(a_len)), (a.blocks().enumerate().chain(iter::repeat(0).enumerate().take(b_len).skip(a_len)),
b.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(0).skip(0))) b.blocks().enumerate().chain(iter::repeat(0).enumerate().take(0).skip(0)))
} else { } else {
(a.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(0).skip(0)), (a.blocks().enumerate().chain(iter::repeat(0).enumerate().take(0).skip(0)),
b.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(a_len).skip(b_len))) b.blocks().enumerate().chain(iter::repeat(0).enumerate().take(a_len).skip(b_len)))
} }
} }
@ -199,7 +199,7 @@ fn blocks_for_bits(bits: usize) -> usize {
/// Computes the bitmask for the final word of the vector /// Computes the bitmask for the final word of the vector
fn mask_for_bits(bits: usize) -> u32 { fn mask_for_bits(bits: usize) -> u32 {
// Note especially that a perfect multiple of u32::BITS should mask all 1s. // Note especially that a perfect multiple of u32::BITS should mask all 1s.
!0u32 >> (u32::BITS as usize - bits % u32::BITS as usize) % u32::BITS as usize !0 >> (u32::BITS as usize - bits % u32::BITS as usize) % u32::BITS as usize
} }
impl BitVec { impl BitVec {
@ -275,7 +275,7 @@ impl BitVec {
pub fn from_elem(nbits: usize, bit: bool) -> BitVec { pub fn from_elem(nbits: usize, bit: bool) -> BitVec {
let nblocks = blocks_for_bits(nbits); let nblocks = blocks_for_bits(nbits);
let mut bit_vec = BitVec { let mut bit_vec = BitVec {
storage: repeat(if bit { !0u32 } else { 0u32 }).take(nblocks).collect(), storage: repeat(if bit { !0 } else { 0 }).take(nblocks).collect(),
nbits: nbits nbits: nbits
}; };
bit_vec.fix_last_block(); bit_vec.fix_last_block();
@ -330,7 +330,7 @@ impl BitVec {
} }
if extra_bytes > 0 { if extra_bytes > 0 {
let mut last_word = 0u32; let mut last_word = 0;
for (i, &byte) in bytes[complete_words*4..].iter().enumerate() { for (i, &byte) in bytes[complete_words*4..].iter().enumerate() {
last_word |= (reverse_bits(byte) as u32) << (i * 8); last_word |= (reverse_bits(byte) as u32) << (i * 8);
} }
@ -431,7 +431,7 @@ impl BitVec {
/// ``` /// ```
#[inline] #[inline]
pub fn set_all(&mut self) { pub fn set_all(&mut self) {
for w in &mut self.storage { *w = !0u32; } for w in &mut self.storage { *w = !0; }
self.fix_last_block(); self.fix_last_block();
} }
@ -566,12 +566,12 @@ impl BitVec {
/// assert_eq!(bv.all(), false); /// assert_eq!(bv.all(), false);
/// ``` /// ```
pub fn all(&self) -> bool { pub fn all(&self) -> bool {
let mut last_word = !0u32; let mut last_word = !0;
// Check that every block but the last is all-ones... // Check that every block but the last is all-ones...
self.blocks().all(|elem| { self.blocks().all(|elem| {
let tmp = last_word; let tmp = last_word;
last_word = elem; last_word = elem;
tmp == !0u32 tmp == !0
// and then check the last one has enough ones // and then check the last one has enough ones
}) && (last_word == mask_for_bits(self.nbits)) }) && (last_word == mask_for_bits(self.nbits))
} }
@ -912,7 +912,7 @@ impl BitVec {
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) { pub fn clear(&mut self) {
for w in &mut self.storage { *w = 0u32; } for w in &mut self.storage { *w = 0; }
} }
} }
@ -2313,7 +2313,7 @@ mod tests {
assert_eq!(bit_vec.iter().collect::<Vec<bool>>(), bools); assert_eq!(bit_vec.iter().collect::<Vec<bool>>(), bools);
let long: Vec<_> = (0i32..10000).map(|i| i % 2 == 0).collect(); let long: Vec<_> = (0..10000).map(|i| i % 2 == 0).collect();
let bit_vec: BitVec = long.iter().map(|n| *n).collect(); let bit_vec: BitVec = long.iter().map(|n| *n).collect();
assert_eq!(bit_vec.iter().collect::<Vec<bool>>(), long) assert_eq!(bit_vec.iter().collect::<Vec<bool>>(), long)
} }

View file

@ -226,7 +226,7 @@
//! Some examples of the output from both traits: //! Some examples of the output from both traits:
//! //!
//! ``` //! ```
//! assert_eq!(format!("{} {:?}", 3i32, 4i32), "3 4"); //! assert_eq!(format!("{} {:?}", 3, 4), "3 4");
//! assert_eq!(format!("{} {:?}", 'a', 'b'), "a 'b'"); //! assert_eq!(format!("{} {:?}", 'a', 'b'), "a 'b'");
//! assert_eq!(format!("{} {:?}", "foo\n", "bar\n"), "foo\n \"bar\\n\""); //! assert_eq!(format!("{} {:?}", "foo\n", "bar\n"), "foo\n \"bar\\n\"");
//! ``` //! ```

View file

@ -2639,7 +2639,7 @@ mod tests {
#[test] #[test]
fn test_bytes_set_memory() { fn test_bytes_set_memory() {
use slice::bytes::MutableByteVector; use slice::bytes::MutableByteVector;
let mut values = [1u8,2,3,4,5]; let mut values = [1,2,3,4,5];
values[0..5].set_memory(0xAB); values[0..5].set_memory(0xAB);
assert!(values == [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]); assert!(values == [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]);
values[2..4].set_memory(0xFF); values[2..4].set_memory(0xFF);
@ -2809,26 +2809,26 @@ mod tests {
fn test_mut_chunks() { fn test_mut_chunks() {
use core::iter::ExactSizeIterator; use core::iter::ExactSizeIterator;
let mut v = [0u8, 1, 2, 3, 4, 5, 6]; let mut v = [0, 1, 2, 3, 4, 5, 6];
assert_eq!(v.chunks_mut(2).len(), 4); assert_eq!(v.chunks_mut(2).len(), 4);
for (i, chunk) in v.chunks_mut(3).enumerate() { for (i, chunk) in v.chunks_mut(3).enumerate() {
for x in chunk { for x in chunk {
*x = i as u8; *x = i as u8;
} }
} }
let result = [0u8, 0, 0, 1, 1, 1, 2]; let result = [0, 0, 0, 1, 1, 1, 2];
assert!(v == result); assert!(v == result);
} }
#[test] #[test]
fn test_mut_chunks_rev() { fn test_mut_chunks_rev() {
let mut v = [0u8, 1, 2, 3, 4, 5, 6]; let mut v = [0, 1, 2, 3, 4, 5, 6];
for (i, chunk) in v.chunks_mut(3).rev().enumerate() { for (i, chunk) in v.chunks_mut(3).rev().enumerate() {
for x in chunk { for x in chunk {
*x = i as u8; *x = i as u8;
} }
} }
let result = [2u8, 2, 2, 1, 1, 1, 0]; let result = [2, 2, 2, 1, 1, 1, 0];
assert!(v == result); assert!(v == result);
} }

View file

@ -383,7 +383,7 @@ macro_rules! utf8_first_byte {
// return the value of $ch updated with continuation byte $byte // return the value of $ch updated with continuation byte $byte
macro_rules! utf8_acc_cont_byte { macro_rules! utf8_acc_cont_byte {
($ch:expr, $byte:expr) => (($ch << 6) | ($byte & 63u8) as u32) ($ch:expr, $byte:expr) => (($ch << 6) | ($byte & 63) as u32)
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -2300,8 +2300,8 @@ mod tests {
#[test] #[test]
fn test_chars_decoding() { fn test_chars_decoding() {
let mut bytes = [0u8; 4]; let mut bytes = [0; 4];
for c in (0u32..0x110000).filter_map(|c| ::core::char::from_u32(c)) { for c in (0..0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let len = c.encode_utf8(&mut bytes).unwrap_or(0); let len = c.encode_utf8(&mut bytes).unwrap_or(0);
let s = ::core::str::from_utf8(&bytes[..len]).unwrap(); let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
if Some(c) != s.chars().next() { if Some(c) != s.chars().next() {
@ -2312,8 +2312,8 @@ mod tests {
#[test] #[test]
fn test_chars_rev_decoding() { fn test_chars_rev_decoding() {
let mut bytes = [0u8; 4]; let mut bytes = [0; 4];
for c in (0u32..0x110000).filter_map(|c| ::core::char::from_u32(c)) { for c in (0..0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let len = c.encode_utf8(&mut bytes).unwrap_or(0); let len = c.encode_utf8(&mut bytes).unwrap_or(0);
let s = ::core::str::from_utf8(&bytes[..len]).unwrap(); let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
if Some(c) != s.chars().rev().next() { if Some(c) != s.chars().rev().next() {

View file

@ -153,7 +153,7 @@ impl String {
} }
} }
const TAG_CONT_U8: u8 = 128u8; const TAG_CONT_U8: u8 = 128;
const REPLACEMENT: &'static [u8] = b"\xEF\xBF\xBD"; // U+FFFD in UTF-8 const REPLACEMENT: &'static [u8] = b"\xEF\xBF\xBD"; // U+FFFD in UTF-8
let total = v.len(); let total = v.len();
fn unsafe_get(xs: &[u8], i: usize) -> u8 { fn unsafe_get(xs: &[u8], i: usize) -> u8 {
@ -195,14 +195,14 @@ impl String {
} }
})} })}
if byte < 128u8 { if byte < 128 {
// subseqidx handles this // subseqidx handles this
} else { } else {
let w = unicode_str::utf8_char_width(byte); let w = unicode_str::utf8_char_width(byte);
match w { match w {
2 => { 2 => {
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 { if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!(); error!();
continue; continue;
} }
@ -220,7 +220,7 @@ impl String {
} }
} }
i += 1; i += 1;
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 { if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!(); error!();
continue; continue;
} }
@ -237,12 +237,12 @@ impl String {
} }
} }
i += 1; i += 1;
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 { if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!(); error!();
continue; continue;
} }
i += 1; i += 1;
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 { if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!(); error!();
continue; continue;
} }
@ -1084,40 +1084,40 @@ mod tests {
fn test_from_utf16() { fn test_from_utf16() {
let pairs = let pairs =
[(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"), [(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
vec![0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16, vec![0xd800, 0xdf45, 0xd800, 0xdf3f,
0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16, 0xd800, 0xdf3b, 0xd800, 0xdf46,
0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16, 0xd800, 0xdf39, 0xd800, 0xdf3b,
0xd800_u16, 0xdf30_u16, 0x000a_u16]), 0xd800, 0xdf30, 0x000a]),
(String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"), (String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
vec![0xd801_u16, 0xdc12_u16, 0xd801_u16, vec![0xd801, 0xdc12, 0xd801,
0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16, 0xdc49, 0xd801, 0xdc2e, 0xd801,
0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc40, 0xd801, 0xdc32, 0xd801,
0xdc4b_u16, 0x0020_u16, 0xd801_u16, 0xdc0f_u16, 0xdc4b, 0x0020, 0xd801, 0xdc0f,
0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16, 0xd801, 0xdc32, 0xd801, 0xdc4d,
0x000a_u16]), 0x000a]),
(String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"), (String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
vec![0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16, vec![0xd800, 0xdf00, 0xd800, 0xdf16,
0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16, 0xd800, 0xdf0b, 0xd800, 0xdf04,
0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16, 0xd800, 0xdf11, 0xd800, 0xdf09,
0x00b7_u16, 0xd800_u16, 0xdf0c_u16, 0xd800_u16, 0x00b7, 0xd800, 0xdf0c, 0xd800,
0xdf04_u16, 0xd800_u16, 0xdf15_u16, 0xd800_u16, 0xdf04, 0xd800, 0xdf15, 0xd800,
0xdf04_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04, 0xd800, 0xdf0b, 0xd800,
0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]), 0xdf09, 0xd800, 0xdf11, 0x000a ]),
(String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"), (String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
vec![0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16, vec![0xd801, 0xdc8b, 0xd801, 0xdc98,
0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16, 0xd801, 0xdc88, 0xd801, 0xdc91,
0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16, 0xd801, 0xdc9b, 0xd801, 0xdc92,
0x0020_u16, 0xd801_u16, 0xdc95_u16, 0xd801_u16, 0x0020, 0xd801, 0xdc95, 0xd801,
0xdc93_u16, 0x0020_u16, 0xd801_u16, 0xdc88_u16, 0xdc93, 0x0020, 0xd801, 0xdc88,
0xd801_u16, 0xdc9a_u16, 0xd801_u16, 0xdc8d_u16, 0xd801, 0xdc9a, 0xd801, 0xdc8d,
0x0020_u16, 0xd801_u16, 0xdc8f_u16, 0xd801_u16, 0x0020, 0xd801, 0xdc8f, 0xd801,
0xdc9c_u16, 0xd801_u16, 0xdc92_u16, 0xd801_u16, 0xdc9c, 0xd801, 0xdc92, 0xd801,
0xdc96_u16, 0xd801_u16, 0xdc86_u16, 0x0020_u16, 0xdc96, 0xd801, 0xdc86, 0x0020,
0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16, 0xd801, 0xdc95, 0xd801, 0xdc86,
0x000a_u16 ]), 0x000a ]),
// Issue #12318, even-numbered non-BMP planes // Issue #12318, even-numbered non-BMP planes
(String::from_str("\u{20000}"), (String::from_str("\u{20000}"),
vec![0xD840, 0xDC00])]; vec![0xD840, 0xDC00])];
@ -1303,7 +1303,7 @@ mod tests {
assert_eq!(1.to_string(), "1"); assert_eq!(1.to_string(), "1");
assert_eq!((-1).to_string(), "-1"); assert_eq!((-1).to_string(), "-1");
assert_eq!(200.to_string(), "200"); assert_eq!(200.to_string(), "200");
assert_eq!(2u8.to_string(), "2"); assert_eq!(2.to_string(), "2");
assert_eq!(true.to_string(), "true"); assert_eq!(true.to_string(), "true");
assert_eq!(false.to_string(), "false"); assert_eq!(false.to_string(), "false");
assert_eq!(("hi".to_string()).to_string(), "hi"); assert_eq!(("hi".to_string()).to_string(), "hi");
@ -1421,7 +1421,7 @@ mod tests {
#[bench] #[bench]
fn from_utf8_lossy_100_invalid(b: &mut Bencher) { fn from_utf8_lossy_100_invalid(b: &mut Bencher) {
let s = repeat(0xf5u8).take(100).collect::<Vec<_>>(); let s = repeat(0xf5).take(100).collect::<Vec<_>>();
b.iter(|| { b.iter(|| {
let _ = String::from_utf8_lossy(&s); let _ = String::from_utf8_lossy(&s);
}); });

View file

@ -22,13 +22,13 @@ use option::Option;
use slice::SliceExt; use slice::SliceExt;
// UTF-8 ranges and tags for encoding characters // UTF-8 ranges and tags for encoding characters
const TAG_CONT: u8 = 0b1000_0000u8; const TAG_CONT: u8 = 0b1000_0000;
const TAG_TWO_B: u8 = 0b1100_0000u8; const TAG_TWO_B: u8 = 0b1100_0000;
const TAG_THREE_B: u8 = 0b1110_0000u8; const TAG_THREE_B: u8 = 0b1110_0000;
const TAG_FOUR_B: u8 = 0b1111_0000u8; const TAG_FOUR_B: u8 = 0b1111_0000;
const MAX_ONE_B: u32 = 0x80u32; const MAX_ONE_B: u32 = 0x80;
const MAX_TWO_B: u32 = 0x800u32; const MAX_TWO_B: u32 = 0x800;
const MAX_THREE_B: u32 = 0x10000u32; const MAX_THREE_B: u32 = 0x10000;
/* /*
Lu Uppercase_Letter an uppercase letter Lu Uppercase_Letter an uppercase letter
@ -413,7 +413,7 @@ impl CharExt for char {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn len_utf16(self) -> usize { fn len_utf16(self) -> usize {
let ch = self as u32; let ch = self as u32;
if (ch & 0xFFFF_u32) == ch { 1 } else { 2 } if (ch & 0xFFFF) == ch { 1 } else { 2 }
} }
#[inline] #[inline]
@ -444,19 +444,19 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
dst[0] = code as u8; dst[0] = code as u8;
Some(1) Some(1)
} else if code < MAX_TWO_B && dst.len() >= 2 { } else if code < MAX_TWO_B && dst.len() >= 2 {
dst[0] = (code >> 6 & 0x1F_u32) as u8 | TAG_TWO_B; dst[0] = (code >> 6 & 0x1F) as u8 | TAG_TWO_B;
dst[1] = (code & 0x3F_u32) as u8 | TAG_CONT; dst[1] = (code & 0x3F) as u8 | TAG_CONT;
Some(2) Some(2)
} else if code < MAX_THREE_B && dst.len() >= 3 { } else if code < MAX_THREE_B && dst.len() >= 3 {
dst[0] = (code >> 12 & 0x0F_u32) as u8 | TAG_THREE_B; dst[0] = (code >> 12 & 0x0F) as u8 | TAG_THREE_B;
dst[1] = (code >> 6 & 0x3F_u32) as u8 | TAG_CONT; dst[1] = (code >> 6 & 0x3F) as u8 | TAG_CONT;
dst[2] = (code & 0x3F_u32) as u8 | TAG_CONT; dst[2] = (code & 0x3F) as u8 | TAG_CONT;
Some(3) Some(3)
} else if dst.len() >= 4 { } else if dst.len() >= 4 {
dst[0] = (code >> 18 & 0x07_u32) as u8 | TAG_FOUR_B; dst[0] = (code >> 18 & 0x07) as u8 | TAG_FOUR_B;
dst[1] = (code >> 12 & 0x3F_u32) as u8 | TAG_CONT; dst[1] = (code >> 12 & 0x3F) as u8 | TAG_CONT;
dst[2] = (code >> 6 & 0x3F_u32) as u8 | TAG_CONT; dst[2] = (code >> 6 & 0x3F) as u8 | TAG_CONT;
dst[3] = (code & 0x3F_u32) as u8 | TAG_CONT; dst[3] = (code & 0x3F) as u8 | TAG_CONT;
Some(4) Some(4)
} else { } else {
None None
@ -472,15 +472,15 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
#[unstable(feature = "core")] #[unstable(feature = "core")]
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> { pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away // Marked #[inline] to allow llvm optimizing it away
if (ch & 0xFFFF_u32) == ch && dst.len() >= 1 { if (ch & 0xFFFF) == ch && dst.len() >= 1 {
// The BMP falls through (assuming non-surrogate, as it should) // The BMP falls through (assuming non-surrogate, as it should)
dst[0] = ch as u16; dst[0] = ch as u16;
Some(1) Some(1)
} else if dst.len() >= 2 { } else if dst.len() >= 2 {
// Supplementary planes break into surrogates. // Supplementary planes break into surrogates.
ch -= 0x1_0000_u32; ch -= 0x1_0000;
dst[0] = 0xD800_u16 | ((ch >> 10) as u16); dst[0] = 0xD800 | ((ch >> 10) as u16);
dst[1] = 0xDC00_u16 | ((ch as u16) & 0x3FF_u16); dst[1] = 0xDC00 | ((ch as u16) & 0x3FF);
Some(2) Some(2)
} else { } else {
None None

View file

@ -123,13 +123,13 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
// For an f64 the exponent is in the range of [-1022, 1023] for base 2, so // For an f64 the exponent is in the range of [-1022, 1023] for base 2, so
// we may have up to that many digits. Give ourselves some extra wiggle room // we may have up to that many digits. Give ourselves some extra wiggle room
// otherwise as well. // otherwise as well.
let mut buf = [0u8; 1536]; let mut buf = [0; 1536];
let mut end = 0; let mut end = 0;
let radix_gen: T = cast(radix as int).unwrap(); let radix_gen: T = cast(radix as int).unwrap();
let (num, exp) = match exp_format { let (num, exp) = match exp_format {
ExpNone => (num, 0i32), ExpNone => (num, 0),
ExpDec if num == _0 => (num, 0i32), ExpDec if num == _0 => (num, 0),
ExpDec => { ExpDec => {
let (exp, exp_base) = match exp_format { let (exp, exp_base) = match exp_format {
ExpDec => (num.abs().log10().floor(), cast::<f64, T>(10.0f64).unwrap()), ExpDec => (num.abs().log10().floor(), cast::<f64, T>(10.0f64).unwrap()),

View file

@ -565,7 +565,7 @@ impl<'a> Formatter<'a> {
Alignment::Center => (padding / 2, (padding + 1) / 2), Alignment::Center => (padding / 2, (padding + 1) / 2),
}; };
let mut fill = [0u8; 4]; let mut fill = [0; 4];
let len = self.fill.encode_utf8(&mut fill).unwrap_or(0); let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
let fill = unsafe { str::from_utf8_unchecked(&fill[..len]) }; let fill = unsafe { str::from_utf8_unchecked(&fill[..len]) };
@ -689,7 +689,7 @@ impl Debug for char {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Display for char { impl Display for char {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
let mut utf8 = [0u8; 4]; let mut utf8 = [0; 4];
let amt = self.encode_utf8(&mut utf8).unwrap_or(0); let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
let s: &str = unsafe { mem::transmute(&utf8[..amt]) }; let s: &str = unsafe { mem::transmute(&utf8[..amt]) };
Display::fmt(s, f) Display::fmt(s, f)

View file

@ -38,7 +38,7 @@ trait GenericRadix {
// characters for a base 2 number. // characters for a base 2 number.
let zero = Int::zero(); let zero = Int::zero();
let is_positive = x >= zero; let is_positive = x >= zero;
let mut buf = [0u8; 64]; let mut buf = [0; 64];
let mut curr = buf.len(); let mut curr = buf.len();
let base = cast(self.base()).unwrap(); let base = cast(self.base()).unwrap();
if is_positive { if is_positive {

View file

@ -60,7 +60,7 @@ macro_rules! u8to64_le {
($buf:expr, $i:expr, $len:expr) => ($buf:expr, $i:expr, $len:expr) =>
({ ({
let mut t = 0; let mut t = 0;
let mut out = 0u64; let mut out = 0;
while t < $len { while t < $len {
out |= ($buf[t+$i] as u64) << t*8; out |= ($buf[t+$i] as u64) << t*8;
t += 1; t += 1;

View file

@ -230,7 +230,7 @@ extern "rust-intrinsic" {
/// use std::mem; /// use std::mem;
/// ///
/// let v: &[u8] = unsafe { mem::transmute("L") }; /// let v: &[u8] = unsafe { mem::transmute("L") };
/// assert!(v == [76u8]); /// assert!(v == [76]);
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn transmute<T,U>(e: T) -> U; pub fn transmute<T,U>(e: T) -> U;

View file

@ -1149,7 +1149,7 @@ pub trait AdditiveIterator<A> {
/// ``` /// ```
/// use std::iter::AdditiveIterator; /// use std::iter::AdditiveIterator;
/// ///
/// let a = [1i32, 2, 3, 4, 5]; /// let a = [1, 2, 3, 4, 5];
/// let mut it = a.iter().cloned(); /// let mut it = a.iter().cloned();
/// assert!(it.sum() == 15); /// assert!(it.sum() == 15);
/// ``` /// ```

View file

@ -227,7 +227,7 @@ macro_rules! writeln {
/// ///
/// ```rust /// ```rust
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3 /// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
/// for i in std::iter::count(0_u32, 1) { /// for i in std::iter::count(0, 1) {
/// if 3*i < i { panic!("u32 overflow"); } /// if 3*i < i { panic!("u32 overflow"); }
/// if x < 3*i { return i-1; } /// if x < 3*i { return i-1; }
/// } /// }

View file

@ -385,7 +385,7 @@ impl<T> Option<T> {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// let k = 10i32; /// let k = 10;
/// assert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4); /// assert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);
/// assert_eq!(None.unwrap_or_else(|| 2 * k), 20); /// assert_eq!(None.unwrap_or_else(|| 2 * k), 20);
/// ``` /// ```

View file

@ -1119,9 +1119,9 @@ pub struct CharRange {
} }
/// Mask of the value bits of a continuation byte /// Mask of the value bits of a continuation byte
const CONT_MASK: u8 = 0b0011_1111u8; const CONT_MASK: u8 = 0b0011_1111;
/// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte /// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte
const TAG_CONT_U8: u8 = 0b1000_0000u8; const TAG_CONT_U8: u8 = 0b1000_0000;
/* /*
Section: Trait implementations Section: Trait implementations
@ -1568,7 +1568,7 @@ impl StrExt for str {
if index == self.len() { return true; } if index == self.len() { return true; }
match self.as_bytes().get(index) { match self.as_bytes().get(index) {
None => false, None => false,
Some(&b) => b < 128u8 || b >= 192u8, Some(&b) => b < 128 || b >= 192,
} }
} }
@ -1680,7 +1680,7 @@ impl StrExt for str {
#[inline] #[inline]
#[unstable(feature = "core")] #[unstable(feature = "core")]
pub fn char_range_at_raw(bytes: &[u8], i: usize) -> (u32, usize) { pub fn char_range_at_raw(bytes: &[u8], i: usize) -> (u32, usize) {
if bytes[i] < 128u8 { if bytes[i] < 128 {
return (bytes[i] as u32, i + 1); return (bytes[i] as u32, i + 1);
} }

View file

@ -165,7 +165,7 @@ fn test_escape_unicode() {
#[test] #[test]
fn test_encode_utf8() { fn test_encode_utf8() {
fn check(input: char, expect: &[u8]) { fn check(input: char, expect: &[u8]) {
let mut buf = [0u8; 4]; let mut buf = [0; 4];
let n = input.encode_utf8(&mut buf).unwrap_or(0); let n = input.encode_utf8(&mut buf).unwrap_or(0);
assert_eq!(&buf[..n], expect); assert_eq!(&buf[..n], expect);
} }
@ -179,7 +179,7 @@ fn test_encode_utf8() {
#[test] #[test]
fn test_encode_utf16() { fn test_encode_utf16() {
fn check(input: char, expect: &[u16]) { fn check(input: char, expect: &[u16]) {
let mut buf = [0u16; 2]; let mut buf = [0; 2];
let n = input.encode_utf16(&mut buf).unwrap_or(0); let n = input.encode_utf16(&mut buf).unwrap_or(0);
assert_eq!(&buf[..n], expect); assert_eq!(&buf[..n], expect);
} }

View file

@ -62,10 +62,10 @@ fn test_writer_hasher() {
// FIXME (#18283) Enable test // FIXME (#18283) Enable test
//let s: Box<str> = box "a"; //let s: Box<str> = box "a";
//assert_eq!(hasher.hash(& s), 97 + 0xFF); //assert_eq!(hasher.hash(& s), 97 + 0xFF);
let cs: &[u8] = &[1u8, 2u8, 3u8]; let cs: &[u8] = &[1, 2, 3];
assert_eq!(hash(& cs), 9); assert_eq!(hash(& cs), 9);
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let cs: Box<[u8]> = Box::new([1u8, 2u8, 3u8]); let cs: Box<[u8]> = Box::new([1, 2, 3]);
assert_eq!(hash(& cs), 9); assert_eq!(hash(& cs), 9);
// FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]> // FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]>

View file

@ -100,8 +100,8 @@ fn test_siphash() {
[ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ] [ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ]
]; ];
let k0 = 0x_07_06_05_04_03_02_01_00_u64; let k0 = 0x_07_06_05_04_03_02_01_00;
let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08;
let mut buf = Vec::new(); let mut buf = Vec::new();
let mut t = 0; let mut t = 0;
let mut state_inc = SipState::new_with_keys(k0, k1); let mut state_inc = SipState::new_with_keys(k0, k1);
@ -230,8 +230,8 @@ fn test_hash_no_concat_alias() {
assert!(s != t && t != u); assert!(s != t && t != u);
assert!(hash(&s) != hash(&t) && hash(&s) != hash(&u)); assert!(hash(&s) != hash(&t) && hash(&s) != hash(&u));
let v: (&[u8], &[u8], &[u8]) = (&[1u8], &[0u8, 0], &[0u8]); let v: (&[u8], &[u8], &[u8]) = (&[1], &[0, 0], &[0]);
let w: (&[u8], &[u8], &[u8]) = (&[1u8, 0, 0, 0], &[], &[]); let w: (&[u8], &[u8], &[u8]) = (&[1, 0, 0, 0], &[], &[]);
assert!(v != w); assert!(v != w);
assert!(hash(&v) != hash(&w)); assert!(hash(&v) != hash(&w));

View file

@ -778,9 +778,9 @@ fn test_range_step() {
assert_eq!(range_step(0, 20, 5).collect::<Vec<int>>(), [0, 5, 10, 15]); assert_eq!(range_step(0, 20, 5).collect::<Vec<int>>(), [0, 5, 10, 15]);
assert_eq!(range_step(20, 0, -5).collect::<Vec<int>>(), [20, 15, 10, 5]); assert_eq!(range_step(20, 0, -5).collect::<Vec<int>>(), [20, 15, 10, 5]);
assert_eq!(range_step(20, 0, -6).collect::<Vec<int>>(), [20, 14, 8, 2]); assert_eq!(range_step(20, 0, -6).collect::<Vec<int>>(), [20, 14, 8, 2]);
assert_eq!(range_step(200u8, 255, 50).collect::<Vec<u8>>(), [200u8, 250]); assert_eq!(range_step(200, 255, 50).collect::<Vec<u8>>(), [200, 250]);
assert_eq!(range_step(200i, -5, 1).collect::<Vec<int>>(), []); assert_eq!(range_step(200, -5, 1).collect::<Vec<int>>(), []);
assert_eq!(range_step(200i, 200, 1).collect::<Vec<int>>(), []); assert_eq!(range_step(200, 200, 1).collect::<Vec<int>>(), []);
} }
#[test] #[test]
@ -788,7 +788,7 @@ fn test_range_step_inclusive() {
assert_eq!(range_step_inclusive(0, 20, 5).collect::<Vec<int>>(), [0, 5, 10, 15, 20]); assert_eq!(range_step_inclusive(0, 20, 5).collect::<Vec<int>>(), [0, 5, 10, 15, 20]);
assert_eq!(range_step_inclusive(20, 0, -5).collect::<Vec<int>>(), [20, 15, 10, 5, 0]); assert_eq!(range_step_inclusive(20, 0, -5).collect::<Vec<int>>(), [20, 15, 10, 5, 0]);
assert_eq!(range_step_inclusive(20, 0, -6).collect::<Vec<int>>(), [20, 14, 8, 2]); assert_eq!(range_step_inclusive(20, 0, -6).collect::<Vec<int>>(), [20, 14, 8, 2]);
assert_eq!(range_step_inclusive(200u8, 255, 50).collect::<Vec<u8>>(), [200u8, 250]); assert_eq!(range_step_inclusive(200, 255, 50).collect::<Vec<u8>>(), [200, 250]);
assert_eq!(range_step_inclusive(200, -5, 1).collect::<Vec<int>>(), []); assert_eq!(range_step_inclusive(200, -5, 1).collect::<Vec<int>>(), []);
assert_eq!(range_step_inclusive(200, 200, 1).collect::<Vec<int>>(), [200]); assert_eq!(range_step_inclusive(200, 200, 1).collect::<Vec<int>>(), [200]);
} }

View file

@ -103,7 +103,7 @@ fn test_transmute() {
} }
unsafe { unsafe {
assert_eq!([76u8], transmute::<_, Vec<u8>>("L".to_string())); assert_eq!([76], transmute::<_, Vec<u8>>("L".to_string()));
} }
} }

View file

@ -88,7 +88,7 @@ mod test {
#[test] #[test]
fn test_int_from_str_overflow() { fn test_int_from_str_overflow() {
let mut i8_val: i8 = 127_i8; let mut i8_val: i8 = 127;
assert_eq!("127".parse::<i8>().ok(), Some(i8_val)); assert_eq!("127".parse::<i8>().ok(), Some(i8_val));
assert_eq!("128".parse::<i8>().ok(), None); assert_eq!("128".parse::<i8>().ok(), None);
@ -96,7 +96,7 @@ mod test {
assert_eq!("-128".parse::<i8>().ok(), Some(i8_val)); assert_eq!("-128".parse::<i8>().ok(), Some(i8_val));
assert_eq!("-129".parse::<i8>().ok(), None); assert_eq!("-129".parse::<i8>().ok(), None);
let mut i16_val: i16 = 32_767_i16; let mut i16_val: i16 = 32_767;
assert_eq!("32767".parse::<i16>().ok(), Some(i16_val)); assert_eq!("32767".parse::<i16>().ok(), Some(i16_val));
assert_eq!("32768".parse::<i16>().ok(), None); assert_eq!("32768".parse::<i16>().ok(), None);
@ -104,7 +104,7 @@ mod test {
assert_eq!("-32768".parse::<i16>().ok(), Some(i16_val)); assert_eq!("-32768".parse::<i16>().ok(), Some(i16_val));
assert_eq!("-32769".parse::<i16>().ok(), None); assert_eq!("-32769".parse::<i16>().ok(), None);
let mut i32_val: i32 = 2_147_483_647_i32; let mut i32_val: i32 = 2_147_483_647;
assert_eq!("2147483647".parse::<i32>().ok(), Some(i32_val)); assert_eq!("2147483647".parse::<i32>().ok(), Some(i32_val));
assert_eq!("2147483648".parse::<i32>().ok(), None); assert_eq!("2147483648".parse::<i32>().ok(), None);
@ -112,7 +112,7 @@ mod test {
assert_eq!("-2147483648".parse::<i32>().ok(), Some(i32_val)); assert_eq!("-2147483648".parse::<i32>().ok(), Some(i32_val));
assert_eq!("-2147483649".parse::<i32>().ok(), None); assert_eq!("-2147483649".parse::<i32>().ok(), None);
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; let mut i64_val: i64 = 9_223_372_036_854_775_807;
assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(i64_val)); assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(i64_val));
assert_eq!("9223372036854775808".parse::<i64>().ok(), None); assert_eq!("9223372036854775808".parse::<i64>().ok(), None);

View file

@ -139,12 +139,12 @@ fn test_ptr_addition() {
fn test_ptr_subtraction() { fn test_ptr_subtraction() {
unsafe { unsafe {
let xs = vec![0,1,2,3,4,5,6,7,8,9]; let xs = vec![0,1,2,3,4,5,6,7,8,9];
let mut idx = 9i8; let mut idx = 9;
let ptr = xs.as_ptr(); let ptr = xs.as_ptr();
while idx >= 0i8 { while idx >= 0 {
assert_eq!(*(ptr.offset(idx as int)), idx as int); assert_eq!(*(ptr.offset(idx as int)), idx as int);
idx = idx - 1i8; idx = idx - 1;
} }
let mut xs_mut = xs; let mut xs_mut = xs;

View file

@ -2203,11 +2203,11 @@ pub mod consts {
pub const _IOFBF : c_int = 0; pub const _IOFBF : c_int = 0;
pub const _IONBF : c_int = 4; pub const _IONBF : c_int = 4;
pub const _IOLBF : c_int = 64; pub const _IOLBF : c_int = 64;
pub const BUFSIZ : c_uint = 512_u32; pub const BUFSIZ : c_uint = 512;
pub const FOPEN_MAX : c_uint = 20_u32; pub const FOPEN_MAX : c_uint = 20;
pub const FILENAME_MAX : c_uint = 260_u32; pub const FILENAME_MAX : c_uint = 260;
pub const L_tmpnam : c_uint = 16_u32; pub const L_tmpnam : c_uint = 16;
pub const TMP_MAX : c_uint = 32767_u32; pub const TMP_MAX : c_uint = 32767;
pub const WSAEINTR: c_int = 10004; pub const WSAEINTR: c_int = 10004;
pub const WSAEBADF: c_int = 10009; pub const WSAEBADF: c_int = 10009;
@ -2584,11 +2584,11 @@ pub mod consts {
pub const _IOFBF : c_int = 0; pub const _IOFBF : c_int = 0;
pub const _IONBF : c_int = 2; pub const _IONBF : c_int = 2;
pub const _IOLBF : c_int = 1; pub const _IOLBF : c_int = 1;
pub const BUFSIZ : c_uint = 8192_u32; pub const BUFSIZ : c_uint = 8192;
pub const FOPEN_MAX : c_uint = 16_u32; pub const FOPEN_MAX : c_uint = 16;
pub const FILENAME_MAX : c_uint = 4096_u32; pub const FILENAME_MAX : c_uint = 4096;
pub const L_tmpnam : c_uint = 20_u32; pub const L_tmpnam : c_uint = 20;
pub const TMP_MAX : c_uint = 238328_u32; pub const TMP_MAX : c_uint = 238328;
} }
pub mod c99 { pub mod c99 {
} }
@ -3450,11 +3450,11 @@ pub mod consts {
pub const _IOFBF : c_int = 0; pub const _IOFBF : c_int = 0;
pub const _IONBF : c_int = 2; pub const _IONBF : c_int = 2;
pub const _IOLBF : c_int = 1; pub const _IOLBF : c_int = 1;
pub const BUFSIZ : c_uint = 1024_u32; pub const BUFSIZ : c_uint = 1024;
pub const FOPEN_MAX : c_uint = 20_u32; pub const FOPEN_MAX : c_uint = 20;
pub const FILENAME_MAX : c_uint = 1024_u32; pub const FILENAME_MAX : c_uint = 1024;
pub const L_tmpnam : c_uint = 1024_u32; pub const L_tmpnam : c_uint = 1024;
pub const TMP_MAX : c_uint = 308915776_u32; pub const TMP_MAX : c_uint = 308915776;
} }
pub mod c99 { pub mod c99 {
} }
@ -3858,11 +3858,11 @@ pub mod consts {
pub const _IOFBF : c_int = 0; pub const _IOFBF : c_int = 0;
pub const _IONBF : c_int = 2; pub const _IONBF : c_int = 2;
pub const _IOLBF : c_int = 1; pub const _IOLBF : c_int = 1;
pub const BUFSIZ : c_uint = 1024_u32; pub const BUFSIZ : c_uint = 1024;
pub const FOPEN_MAX : c_uint = 20_u32; pub const FOPEN_MAX : c_uint = 20;
pub const FILENAME_MAX : c_uint = 1024_u32; pub const FILENAME_MAX : c_uint = 1024;
pub const L_tmpnam : c_uint = 1024_u32; pub const L_tmpnam : c_uint = 1024;
pub const TMP_MAX : c_uint = 308915776_u32; pub const TMP_MAX : c_uint = 308915776;
} }
pub mod c99 { pub mod c99 {
} }
@ -4236,11 +4236,11 @@ pub mod consts {
pub const _IOFBF : c_int = 0; pub const _IOFBF : c_int = 0;
pub const _IONBF : c_int = 2; pub const _IONBF : c_int = 2;
pub const _IOLBF : c_int = 1; pub const _IOLBF : c_int = 1;
pub const BUFSIZ : c_uint = 1024_u32; pub const BUFSIZ : c_uint = 1024;
pub const FOPEN_MAX : c_uint = 20_u32; pub const FOPEN_MAX : c_uint = 20;
pub const FILENAME_MAX : c_uint = 1024_u32; pub const FILENAME_MAX : c_uint = 1024;
pub const L_tmpnam : c_uint = 1024_u32; pub const L_tmpnam : c_uint = 1024;
pub const TMP_MAX : c_uint = 308915776_u32; pub const TMP_MAX : c_uint = 308915776;
} }
pub mod c99 { pub mod c99 {
} }

View file

@ -173,7 +173,7 @@ impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
fn reseed(&mut self, seed: &'a [u32]) { fn reseed(&mut self, seed: &'a [u32]) {
// reset state // reset state
self.init(&[0u32; KEY_WORDS]); self.init(&[0; KEY_WORDS]);
// set key in place // set key in place
let key = &mut self.state[4 .. 4+KEY_WORDS]; let key = &mut self.state[4 .. 4+KEY_WORDS];
for (k, s) in key.iter_mut().zip(seed.iter()) { for (k, s) in key.iter_mut().zip(seed.iter()) {
@ -245,7 +245,7 @@ mod test {
fn test_rng_true_values() { fn test_rng_true_values() {
// Test vectors 1 and 2 from // Test vectors 1 and 2 from
// http://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04 // http://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04
let seed : &[_] = &[0u32; 8]; let seed : &[_] = &[0; 8];
let mut ra: ChaChaRng = SeedableRng::from_seed(seed); let mut ra: ChaChaRng = SeedableRng::from_seed(seed);
let v = (0..16).map(|_| ra.next_u32()).collect::<Vec<_>>(); let v = (0..16).map(|_| ra.next_u32()).collect::<Vec<_>>();
@ -285,7 +285,7 @@ mod test {
#[test] #[test]
fn test_rng_clone() { fn test_rng_clone() {
let seed : &[_] = &[0u32; 8]; let seed : &[_] = &[0; 8];
let mut rng: ChaChaRng = SeedableRng::from_seed(seed); let mut rng: ChaChaRng = SeedableRng::from_seed(seed);
let mut clone = rng.clone(); let mut clone = rng.clone();
for _ in 0..16 { for _ in 0..16 {

View file

@ -23,8 +23,8 @@ use distributions::{Sample, IndependentSample};
/// ///
/// This gives a uniform distribution (assuming the RNG used to sample /// This gives a uniform distribution (assuming the RNG used to sample
/// it is itself uniform & the `SampleRange` implementation for the /// it is itself uniform & the `SampleRange` implementation for the
/// given type is correct), even for edge cases like `low = 0u8`, /// given type is correct), even for edge cases like `low = 0`,
/// `high = 170u8`, for which a naive modulo operation would return /// `high = 170`, for which a naive modulo operation would return
/// numbers less than 85 with double the probability to those greater /// numbers less than 85 with double the probability to those greater
/// than 85. /// than 85.
/// ///

View file

@ -217,7 +217,7 @@ impl<'a> SeedableRng<&'a [u32]> for IsaacRng {
fn reseed(&mut self, seed: &'a [u32]) { fn reseed(&mut self, seed: &'a [u32]) {
// make the seed into [seed[0], seed[1], ..., seed[seed.len() // make the seed into [seed[0], seed[1], ..., seed[seed.len()
// - 1], 0, 0, ...], to fill rng.rsl. // - 1], 0, 0, ...], to fill rng.rsl.
let seed_iter = seed.iter().cloned().chain(repeat(0u32)); let seed_iter = seed.iter().cloned().chain(repeat(0));
for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) { for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) {
*rsl_elem = seed_elem; *rsl_elem = seed_elem;
@ -460,7 +460,7 @@ impl<'a> SeedableRng<&'a [u64]> for Isaac64Rng {
fn reseed(&mut self, seed: &'a [u64]) { fn reseed(&mut self, seed: &'a [u64]) {
// make the seed into [seed[0], seed[1], ..., seed[seed.len() // make the seed into [seed[0], seed[1], ..., seed[seed.len()
// - 1], 0, 0, ...], to fill rng.rsl. // - 1], 0, 0, ...], to fill rng.rsl.
let seed_iter = seed.iter().cloned().chain(repeat(0u64)); let seed_iter = seed.iter().cloned().chain(repeat(0));
for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) { for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) {
*rsl_elem = seed_elem; *rsl_elem = seed_elem;

View file

@ -149,7 +149,7 @@ pub trait Rng : Sized {
/// ```rust /// ```rust
/// use std::rand::{thread_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut v = [0u8; 13579]; /// let mut v = [0; 13579];
/// thread_rng().fill_bytes(&mut v); /// thread_rng().fill_bytes(&mut v);
/// println!("{:?}", v.as_slice()); /// println!("{:?}", v.as_slice());
/// ``` /// ```

View file

@ -215,7 +215,7 @@ mod test {
const FILL_BYTES_V_LEN: uint = 13579; const FILL_BYTES_V_LEN: uint = 13579;
#[test] #[test]
fn test_rng_fill_bytes() { fn test_rng_fill_bytes() {
let mut v = repeat(0u8).take(FILL_BYTES_V_LEN).collect::<Vec<_>>(); let mut v = repeat(0).take(FILL_BYTES_V_LEN).collect::<Vec<_>>();
::test::rng().fill_bytes(&mut v); ::test::rng().fill_bytes(&mut v);
// Sanity test: if we've gotten here, `fill_bytes` has not infinitely // Sanity test: if we've gotten here, `fill_bytes` has not infinitely

View file

@ -290,22 +290,22 @@ pub mod reader {
#[inline(never)] #[inline(never)]
fn vuint_at_slow(data: &[u8], start: uint) -> DecodeResult<Res> { fn vuint_at_slow(data: &[u8], start: uint) -> DecodeResult<Res> {
let a = data[start]; let a = data[start];
if a & 0x80u8 != 0u8 { if a & 0x80 != 0 {
return Ok(Res {val: (a & 0x7fu8) as uint, next: start + 1}); return Ok(Res {val: (a & 0x7f) as uint, next: start + 1});
} }
if a & 0x40u8 != 0u8 { if a & 0x40 != 0 {
return Ok(Res {val: ((a & 0x3fu8) as uint) << 8 | return Ok(Res {val: ((a & 0x3f) as uint) << 8 |
(data[start + 1] as uint), (data[start + 1] as uint),
next: start + 2}); next: start + 2});
} }
if a & 0x20u8 != 0u8 { if a & 0x20 != 0 {
return Ok(Res {val: ((a & 0x1fu8) as uint) << 16 | return Ok(Res {val: ((a & 0x1f) as uint) << 16 |
(data[start + 1] as uint) << 8 | (data[start + 1] as uint) << 8 |
(data[start + 2] as uint), (data[start + 2] as uint),
next: start + 3}); next: start + 3});
} }
if a & 0x10u8 != 0u8 { if a & 0x10 != 0 {
return Ok(Res {val: ((a & 0x0fu8) as uint) << 24 | return Ok(Res {val: ((a & 0x0f) as uint) << 24 |
(data[start + 1] as uint) << 16 | (data[start + 1] as uint) << 16 |
(data[start + 2] as uint) << 8 | (data[start + 2] as uint) << 8 |
(data[start + 3] as uint), (data[start + 3] as uint),
@ -877,11 +877,11 @@ pub mod writer {
fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult { fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
match size { match size {
1 => w.write_all(&[0x80u8 | (n as u8)]), 1 => w.write_all(&[0x80 | (n as u8)]),
2 => w.write_all(&[0x40u8 | ((n >> 8) as u8), n as u8]), 2 => w.write_all(&[0x40 | ((n >> 8) as u8), n as u8]),
3 => w.write_all(&[0x20u8 | ((n >> 16) as u8), (n >> 8) as u8, 3 => w.write_all(&[0x20 | ((n >> 16) as u8), (n >> 8) as u8,
n as u8]), n as u8]),
4 => w.write_all(&[0x10u8 | ((n >> 24) as u8), (n >> 16) as u8, 4 => w.write_all(&[0x10 | ((n >> 24) as u8), (n >> 16) as u8,
(n >> 8) as u8, n as u8]), (n >> 8) as u8, n as u8]),
_ => Err(old_io::IoError { _ => Err(old_io::IoError {
kind: old_io::OtherIoError, kind: old_io::OtherIoError,
@ -930,7 +930,7 @@ pub mod writer {
// Write a placeholder four-byte size. // Write a placeholder four-byte size.
self.size_positions.push(try!(self.writer.tell()) as uint); self.size_positions.push(try!(self.writer.tell()) as uint);
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8]; let zeroes: &[u8] = &[0, 0, 0, 0];
self.writer.write_all(zeroes) self.writer.write_all(zeroes)
} }
@ -1422,9 +1422,9 @@ mod bench {
#[bench] #[bench]
pub fn vuint_at_A_aligned(b: &mut Bencher) { pub fn vuint_at_A_aligned(b: &mut Bencher) {
let data = (0i32..4*100).map(|i| { let data = (0..4*100).map(|i| {
match i % 2 { match i % 2 {
0 => 0x80u8, 0 => 0x80,
_ => i as u8, _ => i as u8,
} }
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
@ -1440,9 +1440,9 @@ mod bench {
#[bench] #[bench]
pub fn vuint_at_A_unaligned(b: &mut Bencher) { pub fn vuint_at_A_unaligned(b: &mut Bencher) {
let data = (0i32..4*100+1).map(|i| { let data = (0..4*100+1).map(|i| {
match i % 2 { match i % 2 {
1 => 0x80u8, 1 => 0x80,
_ => i as u8 _ => i as u8
} }
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
@ -1458,11 +1458,11 @@ mod bench {
#[bench] #[bench]
pub fn vuint_at_D_aligned(b: &mut Bencher) { pub fn vuint_at_D_aligned(b: &mut Bencher) {
let data = (0i32..4*100).map(|i| { let data = (0..4*100).map(|i| {
match i % 4 { match i % 4 {
0 => 0x10u8, 0 => 0x10,
3 => i as u8, 3 => i as u8,
_ => 0u8 _ => 0
} }
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let mut sum = 0; let mut sum = 0;
@ -1477,11 +1477,11 @@ mod bench {
#[bench] #[bench]
pub fn vuint_at_D_unaligned(b: &mut Bencher) { pub fn vuint_at_D_unaligned(b: &mut Bencher) {
let data = (0i32..4*100+1).map(|i| { let data = (0..4*100+1).map(|i| {
match i % 4 { match i % 4 {
1 => 0x10u8, 1 => 0x10,
0 => i as u8, 0 => i as u8,
_ => 0u8 _ => 0
} }
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let mut sum = 0; let mut sum = 0;

View file

@ -537,7 +537,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
ast::ExprBlock(ref block) => { ast::ExprBlock(ref block) => {
match block.expr { match block.expr {
Some(ref expr) => try!(eval_const_expr_partial(tcx, &**expr, ety)), Some(ref expr) => try!(eval_const_expr_partial(tcx, &**expr, ety)),
None => const_int(0i64) None => const_int(0)
} }
} }
ast::ExprTupField(ref base, index) => { ast::ExprTupField(ref base, index) => {

View file

@ -45,7 +45,7 @@ pub fn lev_distance(me: &str, t: &str) -> uint {
fn test_lev_distance() { fn test_lev_distance() {
use std::char::{ from_u32, MAX }; use std::char::{ from_u32, MAX };
// Test bytelength agnosticity // Test bytelength agnosticity
for c in (0u32..MAX as u32) for c in (0..MAX as u32)
.filter_map(|i| from_u32(i)) .filter_map(|i| from_u32(i))
.map(|i| i.to_string()) { .map(|i| i.to_string()) {
assert_eq!(lev_distance(&c[..], &c[..]), 0); assert_eq!(lev_distance(&c[..], &c[..]), 0);

View file

@ -119,7 +119,7 @@ impl FixedBuffer64 {
/// Create a new FixedBuffer64 /// Create a new FixedBuffer64
fn new() -> FixedBuffer64 { fn new() -> FixedBuffer64 {
return FixedBuffer64 { return FixedBuffer64 {
buffer: [0u8; 64], buffer: [0; 64],
buffer_idx: 0 buffer_idx: 0
}; };
} }
@ -258,7 +258,7 @@ pub trait Digest {
/// Convenience function that retrieves the result of a digest as a /// Convenience function that retrieves the result of a digest as a
/// newly allocated vec of bytes. /// newly allocated vec of bytes.
fn result_bytes(&mut self) -> Vec<u8> { fn result_bytes(&mut self) -> Vec<u8> {
let mut buf: Vec<u8> = repeat(0u8).take((self.output_bits()+7)/8).collect(); let mut buf: Vec<u8> = repeat(0).take((self.output_bits()+7)/8).collect();
self.result(&mut buf); self.result(&mut buf);
buf buf
} }
@ -342,7 +342,7 @@ impl Engine256State {
let mut g = self.h6; let mut g = self.h6;
let mut h = self.h7; let mut h = self.h7;
let mut w = [0u32; 64]; let mut w = [0; 64];
// Sha-512 and Sha-256 use basically the same calculations which are implemented // Sha-512 and Sha-256 use basically the same calculations which are implemented
// by these macros. Inlining the calculations seems to result in better generated code. // by these macros. Inlining the calculations seems to result in better generated code.
@ -660,7 +660,7 @@ mod bench {
#[bench] #[bench]
pub fn sha256_10(b: &mut Bencher) { pub fn sha256_10(b: &mut Bencher) {
let mut sh = Sha256::new(); let mut sh = Sha256::new();
let bytes = [1u8; 10]; let bytes = [1; 10];
b.iter(|| { b.iter(|| {
sh.input(&bytes); sh.input(&bytes);
}); });
@ -670,7 +670,7 @@ mod bench {
#[bench] #[bench]
pub fn sha256_1k(b: &mut Bencher) { pub fn sha256_1k(b: &mut Bencher) {
let mut sh = Sha256::new(); let mut sh = Sha256::new();
let bytes = [1u8; 1024]; let bytes = [1; 1024];
b.iter(|| { b.iter(|| {
sh.input(&bytes); sh.input(&bytes);
}); });
@ -680,7 +680,7 @@ mod bench {
#[bench] #[bench]
pub fn sha256_64k(b: &mut Bencher) { pub fn sha256_64k(b: &mut Bencher) {
let mut sh = Sha256::new(); let mut sh = Sha256::new();
let bytes = [1u8; 65536]; let bytes = [1; 65536];
b.iter(|| { b.iter(|| {
sh.input(&bytes); sh.input(&bytes);
}); });

View file

@ -316,7 +316,7 @@ mod tests {
bitflags! { bitflags! {
flags AnotherSetOfFlags: i8 { flags AnotherSetOfFlags: i8 {
const AnotherFlag = -1_i8, const AnotherFlag = -1,
} }
} }
@ -327,7 +327,7 @@ mod tests {
assert_eq!(FlagABC.bits(), 0b00000111); assert_eq!(FlagABC.bits(), 0b00000111);
assert_eq!(AnotherSetOfFlags::empty().bits(), 0b00); assert_eq!(AnotherSetOfFlags::empty().bits(), 0b00);
assert_eq!(AnotherFlag.bits(), !0_i8); assert_eq!(AnotherFlag.bits(), !0);
} }
#[test] #[test]
@ -338,7 +338,7 @@ mod tests {
assert!(Flags::from_bits(0b11) == Some(FlagA | FlagB)); assert!(Flags::from_bits(0b11) == Some(FlagA | FlagB));
assert!(Flags::from_bits(0b1000) == None); assert!(Flags::from_bits(0b1000) == None);
assert!(AnotherSetOfFlags::from_bits(!0_i8) == Some(AnotherFlag)); assert!(AnotherSetOfFlags::from_bits(!0) == Some(AnotherFlag));
} }
#[test] #[test]
@ -350,7 +350,7 @@ mod tests {
assert!(Flags::from_bits_truncate(0b1000) == Flags::empty()); assert!(Flags::from_bits_truncate(0b1000) == Flags::empty());
assert!(Flags::from_bits_truncate(0b1001) == FlagA); assert!(Flags::from_bits_truncate(0b1001) == FlagA);
assert!(AnotherSetOfFlags::from_bits_truncate(0_i8) == AnotherSetOfFlags::empty()); assert!(AnotherSetOfFlags::from_bits_truncate(0) == AnotherSetOfFlags::empty());
} }
#[test] #[test]

View file

@ -833,11 +833,11 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
let (is_zero, is_signed) = match rhs_t.sty { let (is_zero, is_signed) = match rhs_t.sty {
ty::ty_int(t) => { ty::ty_int(t) => {
let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0u64, false); let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0, false);
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), true) (ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), true)
} }
ty::ty_uint(t) => { ty::ty_uint(t) => {
let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0u64, false); let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0, false);
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), false) (ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), false)
} }
_ => { _ => {

View file

@ -117,7 +117,7 @@ fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType {
let size = ty_size(ty); let size = ty_size(ty);
if size <= 16 { if size <= 16 {
let llty = if size == 0 { let llty = if size == 0 {
Type::array(&Type::i64(ccx), 0u64) Type::array(&Type::i64(ccx), 0)
} else if size == 1 { } else if size == 1 {
Type::i8(ccx) Type::i8(ccx)
} else if size == 2 { } else if size == 2 {

View file

@ -117,7 +117,7 @@ impl FromHex for str {
// This may be an overestimate if there is any whitespace // This may be an overestimate if there is any whitespace
let mut b = Vec::with_capacity(self.len() / 2); let mut b = Vec::with_capacity(self.len() / 2);
let mut modulus = 0; let mut modulus = 0;
let mut buf = 0u8; let mut buf = 0;
for (idx, byte) in self.bytes().enumerate() { for (idx, byte) in self.bytes().enumerate() {
buf <<= 4; buf <<= 4;

View file

@ -1653,7 +1653,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
fn decode_hex_escape(&mut self) -> Result<u16, ParserError> { fn decode_hex_escape(&mut self) -> Result<u16, ParserError> {
let mut i = 0; let mut i = 0;
let mut n = 0u16; let mut n = 0;
while i < 4 && !self.eof() { while i < 4 && !self.eof() {
self.bump(); self.bump();
n = match self.ch_or_null() { n = match self.ch_or_null() {

View file

@ -186,7 +186,7 @@ impl OwnedAsciiExt for Vec<u8> {
impl AsciiExt for u8 { impl AsciiExt for u8 {
type Owned = u8; type Owned = u8;
#[inline] #[inline]
fn is_ascii(&self) -> bool { *self & 128 == 0u8 } fn is_ascii(&self) -> bool { *self & 128 == 0 }
#[inline] #[inline]
fn to_ascii_uppercase(&self) -> u8 { ASCII_UPPERCASE_MAP[*self as usize] } fn to_ascii_uppercase(&self) -> u8 { ASCII_UPPERCASE_MAP[*self as usize] }
#[inline] #[inline]
@ -398,7 +398,7 @@ mod tests {
assert_eq!("url()URL()uRl()ürl".to_ascii_uppercase(), "URL()URL()URL()üRL"); assert_eq!("url()URL()uRl()ürl".to_ascii_uppercase(), "URL()URL()URL()üRL");
assert_eq!("hıß".to_ascii_uppercase(), "Hıß"); assert_eq!("hıß".to_ascii_uppercase(), "Hıß");
for i in 0u32..501 { for i in 0..501 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i }; else { i };
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_uppercase(), assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_uppercase(),
@ -412,7 +412,7 @@ mod tests {
// Dotted capital I, Kelvin sign, Sharp S. // Dotted capital I, Kelvin sign, Sharp S.
assert_eq!("ß".to_ascii_lowercase(), "ß"); assert_eq!("ß".to_ascii_lowercase(), "ß");
for i in 0u32..501 { for i in 0..501 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i }; else { i };
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lowercase(), assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lowercase(),
@ -426,7 +426,7 @@ mod tests {
"URL()URL()URL()üRL".to_string()); "URL()URL()URL()üRL".to_string());
assert_eq!(("hıß".to_string()).into_ascii_uppercase(), "Hıß"); assert_eq!(("hıß".to_string()).into_ascii_uppercase(), "Hıß");
for i in 0u32..501 { for i in 0..501 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i }; else { i };
assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_uppercase(), assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_uppercase(),
@ -441,7 +441,7 @@ mod tests {
// Dotted capital I, Kelvin sign, Sharp S. // Dotted capital I, Kelvin sign, Sharp S.
assert_eq!(("ß".to_string()).into_ascii_lowercase(), "ß"); assert_eq!(("ß".to_string()).into_ascii_lowercase(), "ß");
for i in 0u32..501 { for i in 0..501 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i }; else { i };
assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_lowercase(), assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_lowercase(),
@ -459,7 +459,7 @@ mod tests {
assert!(!"".eq_ignore_ascii_case("k")); assert!(!"".eq_ignore_ascii_case("k"));
assert!(!"ß".eq_ignore_ascii_case("s")); assert!(!"ß".eq_ignore_ascii_case("s"));
for i in 0u32..501 { for i in 0..501 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i }; else { i };
assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case( assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case(

View file

@ -28,7 +28,7 @@ use ptr::{self, PtrExt, Unique};
use rt::heap::{allocate, deallocate, EMPTY}; use rt::heap::{allocate, deallocate, EMPTY};
use collections::hash_state::HashState; use collections::hash_state::HashState;
const EMPTY_BUCKET: u64 = 0u64; const EMPTY_BUCKET: u64 = 0;
/// The raw hashtable, providing safe-ish access to the unzipped and highly /// The raw hashtable, providing safe-ish access to the unzipped and highly
/// optimized arrays of hashes, keys, and values. /// optimized arrays of hashes, keys, and values.
@ -149,7 +149,7 @@ pub fn make_hash<T: ?Sized, S>(hash_state: &S, t: &T) -> SafeHash
{ {
let mut state = hash_state.hasher(); let mut state = hash_state.hasher();
t.hash(&mut state); t.hash(&mut state);
// We need to avoid 0u64 in order to prevent collisions with // We need to avoid 0 in order to prevent collisions with
// EMPTY_HASH. We can maintain our precious uniform distribution // EMPTY_HASH. We can maintain our precious uniform distribution
// of initial indexes by unconditionally setting the MSB, // of initial indexes by unconditionally setting the MSB,
// effectively reducing 64-bits hashes to 63 bits. // effectively reducing 64-bits hashes to 63 bits.

View file

@ -1053,7 +1053,7 @@ mod tests {
check!(w.write(msg)); check!(w.write(msg));
} }
let files = check!(fs::read_dir(dir)); let files = check!(fs::read_dir(dir));
let mut mem = [0u8; 4]; let mut mem = [0; 4];
for f in files { for f in files {
let f = f.unwrap().path(); let f = f.unwrap().path();
{ {
@ -1083,7 +1083,7 @@ mod tests {
check!(File::create(&dir2.join("14"))); check!(File::create(&dir2.join("14")));
let files = check!(fs::walk_dir(dir)); let files = check!(fs::walk_dir(dir));
let mut cur = [0u8; 2]; let mut cur = [0; 2];
for f in files { for f in files {
let f = f.unwrap().path(); let f = f.unwrap().path();
let stem = f.file_stem().unwrap().to_str().unwrap(); let stem = f.file_stem().unwrap().to_str().unwrap();

View file

@ -616,14 +616,14 @@ mod tests {
#[test] #[test]
fn read_char_buffered() { fn read_char_buffered() {
let buf = [195u8, 159u8]; let buf = [195, 159];
let reader = BufReader::with_capacity(1, &buf[..]); let reader = BufReader::with_capacity(1, &buf[..]);
assert_eq!(reader.chars().next(), Some(Ok('ß'))); assert_eq!(reader.chars().next(), Some(Ok('ß')));
} }
#[test] #[test]
fn test_chars() { fn test_chars() {
let buf = [195u8, 159u8, b'a']; let buf = [195, 159, b'a'];
let reader = BufReader::with_capacity(1, &buf[..]); let reader = BufReader::with_capacity(1, &buf[..]);
let mut it = reader.chars(); let mut it = reader.chars();
assert_eq!(it.next(), Some(Ok('ß'))); assert_eq!(it.next(), Some(Ok('ß')));

View file

@ -237,7 +237,7 @@ mod tests {
#[test] #[test]
fn test_mem_reader() { fn test_mem_reader() {
let mut reader = Cursor::new(vec!(0u8, 1, 2, 3, 4, 5, 6, 7)); let mut reader = Cursor::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
let mut buf = []; let mut buf = [];
assert_eq!(reader.read(&mut buf), Ok(0)); assert_eq!(reader.read(&mut buf), Ok(0));
assert_eq!(reader.position(), 0); assert_eq!(reader.position(), 0);
@ -259,7 +259,7 @@ mod tests {
#[test] #[test]
fn read_to_end() { fn read_to_end() {
let mut reader = Cursor::new(vec!(0u8, 1, 2, 3, 4, 5, 6, 7)); let mut reader = Cursor::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
let mut v = Vec::new(); let mut v = Vec::new();
reader.read_to_end(&mut v).ok().unwrap(); reader.read_to_end(&mut v).ok().unwrap();
assert_eq!(v, [0, 1, 2, 3, 4, 5, 6, 7]); assert_eq!(v, [0, 1, 2, 3, 4, 5, 6, 7]);
@ -267,7 +267,7 @@ mod tests {
#[test] #[test]
fn test_slice_reader() { fn test_slice_reader() {
let in_buf = vec![0u8, 1, 2, 3, 4, 5, 6, 7]; let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
let mut reader = &mut in_buf.as_slice(); let mut reader = &mut in_buf.as_slice();
let mut buf = []; let mut buf = [];
assert_eq!(reader.read(&mut buf), Ok(0)); assert_eq!(reader.read(&mut buf), Ok(0));
@ -289,7 +289,7 @@ mod tests {
#[test] #[test]
fn test_buf_reader() { fn test_buf_reader() {
let in_buf = vec![0u8, 1, 2, 3, 4, 5, 6, 7]; let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
let mut reader = Cursor::new(in_buf.as_slice()); let mut reader = Cursor::new(in_buf.as_slice());
let mut buf = []; let mut buf = [];
assert_eq!(reader.read(&mut buf), Ok(0)); assert_eq!(reader.read(&mut buf), Ok(0));
@ -335,7 +335,7 @@ mod tests {
assert_eq!(r.seek(SeekFrom::Start(10)), Ok(10)); assert_eq!(r.seek(SeekFrom::Start(10)), Ok(10));
assert_eq!(r.read(&mut [0]), Ok(0)); assert_eq!(r.read(&mut [0]), Ok(0));
let mut r = Cursor::new(vec!(10u8)); let mut r = Cursor::new(vec!(10));
assert_eq!(r.seek(SeekFrom::Start(10)), Ok(10)); assert_eq!(r.seek(SeekFrom::Start(10)), Ok(10));
assert_eq!(r.read(&mut [0]), Ok(0)); assert_eq!(r.read(&mut [0]), Ok(0));
@ -347,11 +347,11 @@ mod tests {
#[test] #[test]
fn seek_before_0() { fn seek_before_0() {
let buf = [0xff_u8]; let buf = [0xff];
let mut r = Cursor::new(&buf[..]); let mut r = Cursor::new(&buf[..]);
assert!(r.seek(SeekFrom::End(-2)).is_err()); assert!(r.seek(SeekFrom::End(-2)).is_err());
let mut r = Cursor::new(vec!(10u8)); let mut r = Cursor::new(vec!(10));
assert!(r.seek(SeekFrom::End(-2)).is_err()); assert!(r.seek(SeekFrom::End(-2)).is_err());
let mut buf = [0]; let mut buf = [0];

View file

@ -562,7 +562,7 @@ mod tests {
#[test] #[test]
fn to_socket_addr_ipaddr_u16() { fn to_socket_addr_ipaddr_u16() {
let a = IpAddr::new_v4(77, 88, 21, 11); let a = IpAddr::new_v4(77, 88, 21, 11);
let p = 12345u16; let p = 12345;
let e = SocketAddr::new(a, p); let e = SocketAddr::new(a, p);
assert_eq!(Ok(vec![e]), tsa((a, p))); assert_eq!(Ok(vec![e]), tsa((a, p)));
} }
@ -570,13 +570,13 @@ mod tests {
#[test] #[test]
fn to_socket_addr_str_u16() { fn to_socket_addr_str_u16() {
let a = SocketAddr::new(IpAddr::new_v4(77, 88, 21, 11), 24352); let a = SocketAddr::new(IpAddr::new_v4(77, 88, 21, 11), 24352);
assert_eq!(Ok(vec![a]), tsa(("77.88.21.11", 24352u16))); assert_eq!(Ok(vec![a]), tsa(("77.88.21.11", 24352)));
let a = SocketAddr::new(IpAddr::new_v6(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53); let a = SocketAddr::new(IpAddr::new_v6(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53);
assert_eq!(Ok(vec![a]), tsa(("2a02:6b8:0:1::1", 53))); assert_eq!(Ok(vec![a]), tsa(("2a02:6b8:0:1::1", 53)));
let a = SocketAddr::new(IpAddr::new_v4(127, 0, 0, 1), 23924); let a = SocketAddr::new(IpAddr::new_v4(127, 0, 0, 1), 23924);
assert!(tsa(("localhost", 23924u16)).unwrap().contains(&a)); assert!(tsa(("localhost", 23924)).unwrap().contains(&a));
} }
#[test] #[test]

View file

@ -136,7 +136,7 @@ impl<'a> Parser<'a> {
} }
fn read_number_impl(&mut self, radix: u8, max_digits: u32, upto: u32) -> Option<u32> { fn read_number_impl(&mut self, radix: u8, max_digits: u32, upto: u32) -> Option<u32> {
let mut r = 0u32; let mut r = 0;
let mut digit_count = 0; let mut digit_count = 0;
loop { loop {
match self.read_digit(radix) { match self.read_digit(radix) {
@ -164,7 +164,7 @@ impl<'a> Parser<'a> {
} }
fn read_ipv4_addr_impl(&mut self) -> Option<Ipv4Addr> { fn read_ipv4_addr_impl(&mut self) -> Option<Ipv4Addr> {
let mut bs = [0u8; 4]; let mut bs = [0; 4];
let mut i = 0; let mut i = 0;
while i < 4 { while i < 4 {
if i != 0 && self.read_given_char('.').is_none() { if i != 0 && self.read_given_char('.').is_none() {
@ -189,7 +189,7 @@ impl<'a> Parser<'a> {
fn read_ipv6_addr_impl(&mut self) -> Option<Ipv6Addr> { fn read_ipv6_addr_impl(&mut self) -> Option<Ipv6Addr> {
fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> Ipv6Addr { fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> Ipv6Addr {
assert!(head.len() + tail.len() <= 8); assert!(head.len() + tail.len() <= 8);
let mut gs = [0u16; 8]; let mut gs = [0; 8];
gs.clone_from_slice(head); gs.clone_from_slice(head);
gs[(8 - tail.len()) .. 8].clone_from_slice(tail); gs[(8 - tail.len()) .. 8].clone_from_slice(tail);
Ipv6Addr::new(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7]) Ipv6Addr::new(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7])
@ -231,7 +231,7 @@ impl<'a> Parser<'a> {
(i, false) (i, false)
} }
let mut head = [0u16; 8]; let mut head = [0; 8];
let (head_size, head_ipv4) = read_groups(self, &mut head, 8); let (head_size, head_ipv4) = read_groups(self, &mut head, 8);
if head_size == 8 { if head_size == 8 {
@ -250,7 +250,7 @@ impl<'a> Parser<'a> {
return None; return None;
} }
let mut tail = [0u16; 8]; let mut tail = [0; 8];
let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size); let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size);
Some(ipv6_addr_from_head_tail(&head[..head_size], &tail[..tail_size])) Some(ipv6_addr_from_head_tail(&head[..head_size], &tail[..tail_size]))
} }

View file

@ -824,14 +824,14 @@ mod tests {
#[test] #[test]
fn test_integer_decode() { fn test_integer_decode() {
assert_eq!(3.14159265359f32.integer_decode(), (13176795u64, -22i16, 1i8)); assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
assert_eq!((-8573.5918555f32).integer_decode(), (8779358u64, -10i16, -1i8)); assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1));
assert_eq!(2f32.powf(100.0).integer_decode(), (8388608u64, 77i16, 1i8)); assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1));
assert_eq!(0f32.integer_decode(), (0u64, -150i16, 1i8)); assert_eq!(0f32.integer_decode(), (0, -150, 1));
assert_eq!((-0f32).integer_decode(), (0u64, -150i16, -1i8)); assert_eq!((-0f32).integer_decode(), (0, -150, -1));
assert_eq!(INFINITY.integer_decode(), (8388608u64, 105i16, 1i8)); assert_eq!(INFINITY.integer_decode(), (8388608, 105, 1));
assert_eq!(NEG_INFINITY.integer_decode(), (8388608u64, 105i16, -1i8)); assert_eq!(NEG_INFINITY.integer_decode(), (8388608, 105, -1));
assert_eq!(NAN.integer_decode(), (12582912u64, 105i16, 1i8)); assert_eq!(NAN.integer_decode(), (12582912, 105, 1));
} }
#[test] #[test]

View file

@ -826,14 +826,14 @@ mod tests {
#[test] #[test]
fn test_integer_decode() { fn test_integer_decode() {
assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906u64, -51i16, 1i8)); assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1));
assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931u64, -39i16, -1i8)); assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1));
assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496u64, 48i16, 1i8)); assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1));
assert_eq!(0f64.integer_decode(), (0u64, -1075i16, 1i8)); assert_eq!(0f64.integer_decode(), (0, -1075, 1));
assert_eq!((-0f64).integer_decode(), (0u64, -1075i16, -1i8)); assert_eq!((-0f64).integer_decode(), (0, -1075, -1));
assert_eq!(INFINITY.integer_decode(), (4503599627370496u64, 972i16, 1i8)); assert_eq!(INFINITY.integer_decode(), (4503599627370496, 972, 1));
assert_eq!(NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1)); assert_eq!(NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1));
assert_eq!(NAN.integer_decode(), (6755399441055744u64, 972i16, 1i8)); assert_eq!(NAN.integer_decode(), (6755399441055744, 972, 1));
} }
#[test] #[test]

View file

@ -312,7 +312,7 @@ pub trait Float
/// ///
/// let num = 2.0f32; /// let num = 2.0f32;
/// ///
/// // (8388608u64, -22i16, 1i8) /// // (8388608, -22, 1)
/// let (mantissa, exponent, sign) = num.integer_decode(); /// let (mantissa, exponent, sign) = num.integer_decode();
/// let sign_f = sign as f32; /// let sign_f = sign as f32;
/// let mantissa_f = mantissa as f32; /// let mantissa_f = mantissa as f32;
@ -1755,25 +1755,25 @@ mod tests {
#[test] #[test]
fn test_uint_to_str_overflow() { fn test_uint_to_str_overflow() {
let mut u8_val: u8 = 255_u8; let mut u8_val: u8 = 255;
assert_eq!(u8_val.to_string(), "255"); assert_eq!(u8_val.to_string(), "255");
u8_val = u8_val.wrapping_add(1); u8_val = u8_val.wrapping_add(1);
assert_eq!(u8_val.to_string(), "0"); assert_eq!(u8_val.to_string(), "0");
let mut u16_val: u16 = 65_535_u16; let mut u16_val: u16 = 65_535;
assert_eq!(u16_val.to_string(), "65535"); assert_eq!(u16_val.to_string(), "65535");
u16_val = u16_val.wrapping_add(1); u16_val = u16_val.wrapping_add(1);
assert_eq!(u16_val.to_string(), "0"); assert_eq!(u16_val.to_string(), "0");
let mut u32_val: u32 = 4_294_967_295_u32; let mut u32_val: u32 = 4_294_967_295;
assert_eq!(u32_val.to_string(), "4294967295"); assert_eq!(u32_val.to_string(), "4294967295");
u32_val = u32_val.wrapping_add(1); u32_val = u32_val.wrapping_add(1);
assert_eq!(u32_val.to_string(), "0"); assert_eq!(u32_val.to_string(), "0");
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; let mut u64_val: u64 = 18_446_744_073_709_551_615;
assert_eq!(u64_val.to_string(), "18446744073709551615"); assert_eq!(u64_val.to_string(), "18446744073709551615");
u64_val = u64_val.wrapping_add(1); u64_val = u64_val.wrapping_add(1);
@ -1786,7 +1786,7 @@ mod tests {
#[test] #[test]
fn test_uint_from_str_overflow() { fn test_uint_from_str_overflow() {
let mut u8_val: u8 = 255_u8; let mut u8_val: u8 = 255;
assert_eq!(from_str::<u8>("255"), Some(u8_val)); assert_eq!(from_str::<u8>("255"), Some(u8_val));
assert_eq!(from_str::<u8>("256"), None); assert_eq!(from_str::<u8>("256"), None);
@ -1794,7 +1794,7 @@ mod tests {
assert_eq!(from_str::<u8>("0"), Some(u8_val)); assert_eq!(from_str::<u8>("0"), Some(u8_val));
assert_eq!(from_str::<u8>("-1"), None); assert_eq!(from_str::<u8>("-1"), None);
let mut u16_val: u16 = 65_535_u16; let mut u16_val: u16 = 65_535;
assert_eq!(from_str::<u16>("65535"), Some(u16_val)); assert_eq!(from_str::<u16>("65535"), Some(u16_val));
assert_eq!(from_str::<u16>("65536"), None); assert_eq!(from_str::<u16>("65536"), None);
@ -1802,7 +1802,7 @@ mod tests {
assert_eq!(from_str::<u16>("0"), Some(u16_val)); assert_eq!(from_str::<u16>("0"), Some(u16_val));
assert_eq!(from_str::<u16>("-1"), None); assert_eq!(from_str::<u16>("-1"), None);
let mut u32_val: u32 = 4_294_967_295_u32; let mut u32_val: u32 = 4_294_967_295;
assert_eq!(from_str::<u32>("4294967295"), Some(u32_val)); assert_eq!(from_str::<u32>("4294967295"), Some(u32_val));
assert_eq!(from_str::<u32>("4294967296"), None); assert_eq!(from_str::<u32>("4294967296"), None);
@ -1810,7 +1810,7 @@ mod tests {
assert_eq!(from_str::<u32>("0"), Some(u32_val)); assert_eq!(from_str::<u32>("0"), Some(u32_val));
assert_eq!(from_str::<u32>("-1"), None); assert_eq!(from_str::<u32>("-1"), None);
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; let mut u64_val: u64 = 18_446_744_073_709_551_615;
assert_eq!(from_str::<u64>("18446744073709551615"), Some(u64_val)); assert_eq!(from_str::<u64>("18446744073709551615"), Some(u64_val));
assert_eq!(from_str::<u64>("18446744073709551616"), None); assert_eq!(from_str::<u64>("18446744073709551616"), None);

View file

@ -104,7 +104,7 @@ fn int_to_str_bytes_common<T, F>(num: T, radix: uint, sign: SignFormat, mut f: F
// This is just for integral types, the largest of which is a u64. The // This is just for integral types, the largest of which is a u64. The
// smallest base that we can have is 2, so the most number of digits we're // smallest base that we can have is 2, so the most number of digits we're
// ever going to have is 64 // ever going to have is 64
let mut buf = [0u8; 64]; let mut buf = [0; 64];
let mut cur = 0; let mut cur = 0;
// Loop at least once to make sure at least a `0` gets emitted. // Loop at least once to make sure at least a `0` gets emitted.
@ -221,10 +221,10 @@ pub fn float_to_str_bytes_common<T: Float>(
let radix_gen: T = num::cast(radix as int).unwrap(); let radix_gen: T = num::cast(radix as int).unwrap();
let (num, exp) = match exp_format { let (num, exp) = match exp_format {
ExpNone => (num, 0i32), ExpNone => (num, 0),
ExpDec | ExpBin => { ExpDec | ExpBin => {
if num == _0 { if num == _0 {
(num, 0i32) (num, 0)
} else { } else {
let (exp, exp_base) = match exp_format { let (exp, exp_base) = match exp_format {
ExpDec => (num.abs().log10().floor(), num::cast::<f64, T>(10.0f64).unwrap()), ExpDec => (num.abs().log10().floor(), num::cast::<f64, T>(10.0f64).unwrap()),
@ -432,25 +432,25 @@ mod tests {
#[test] #[test]
fn test_int_to_str_overflow() { fn test_int_to_str_overflow() {
let mut i8_val: i8 = 127_i8; let mut i8_val: i8 = 127;
assert_eq!(i8_val.to_string(), "127"); assert_eq!(i8_val.to_string(), "127");
i8_val = i8_val.wrapping_add(1); i8_val = i8_val.wrapping_add(1);
assert_eq!(i8_val.to_string(), "-128"); assert_eq!(i8_val.to_string(), "-128");
let mut i16_val: i16 = 32_767_i16; let mut i16_val: i16 = 32_767;
assert_eq!(i16_val.to_string(), "32767"); assert_eq!(i16_val.to_string(), "32767");
i16_val = i16_val.wrapping_add(1); i16_val = i16_val.wrapping_add(1);
assert_eq!(i16_val.to_string(), "-32768"); assert_eq!(i16_val.to_string(), "-32768");
let mut i32_val: i32 = 2_147_483_647_i32; let mut i32_val: i32 = 2_147_483_647;
assert_eq!(i32_val.to_string(), "2147483647"); assert_eq!(i32_val.to_string(), "2147483647");
i32_val = i32_val.wrapping_add(1); i32_val = i32_val.wrapping_add(1);
assert_eq!(i32_val.to_string(), "-2147483648"); assert_eq!(i32_val.to_string(), "-2147483648");
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; let mut i64_val: i64 = 9_223_372_036_854_775_807;
assert_eq!(i64_val.to_string(), "9223372036854775807"); assert_eq!(i64_val.to_string(), "9223372036854775807");
i64_val = i64_val.wrapping_add(1); i64_val = i64_val.wrapping_add(1);

View file

@ -642,14 +642,14 @@ mod test {
#[test] #[test]
fn read_char_buffered() { fn read_char_buffered() {
let buf = [195u8, 159u8]; let buf = [195, 159];
let mut reader = BufferedReader::with_capacity(1, &buf[..]); let mut reader = BufferedReader::with_capacity(1, &buf[..]);
assert_eq!(reader.read_char(), Ok('ß')); assert_eq!(reader.read_char(), Ok('ß'));
} }
#[test] #[test]
fn test_chars() { fn test_chars() {
let buf = [195u8, 159u8, b'a']; let buf = [195, 159, b'a'];
let mut reader = BufferedReader::with_capacity(1, &buf[..]); let mut reader = BufferedReader::with_capacity(1, &buf[..]);
let mut it = reader.chars(); let mut it = reader.chars();
assert_eq!(it.next(), Some(Ok('ß'))); assert_eq!(it.next(), Some(Ok('ß')));

View file

@ -30,7 +30,7 @@ use vec::Vec;
/// # drop(tx); /// # drop(tx);
/// let mut reader = ChanReader::new(rx); /// let mut reader = ChanReader::new(rx);
/// ///
/// let mut buf = [0u8; 100]; /// let mut buf = [0; 100];
/// match reader.read(&mut buf) { /// match reader.read(&mut buf) {
/// Ok(nread) => println!("Read {} bytes", nread), /// Ok(nread) => println!("Read {} bytes", nread),
/// Err(e) => println!("read error: {}", e), /// Err(e) => println!("read error: {}", e),
@ -167,15 +167,15 @@ mod test {
fn test_rx_reader() { fn test_rx_reader() {
let (tx, rx) = channel(); let (tx, rx) = channel();
thread::spawn(move|| { thread::spawn(move|| {
tx.send(vec![1u8, 2u8]).unwrap(); tx.send(vec![1, 2]).unwrap();
tx.send(vec![]).unwrap(); tx.send(vec![]).unwrap();
tx.send(vec![3u8, 4u8]).unwrap(); tx.send(vec![3, 4]).unwrap();
tx.send(vec![5u8, 6u8]).unwrap(); tx.send(vec![5, 6]).unwrap();
tx.send(vec![7u8, 8u8]).unwrap(); tx.send(vec![7, 8]).unwrap();
}); });
let mut reader = ChanReader::new(rx); let mut reader = ChanReader::new(rx);
let mut buf = [0u8; 3]; let mut buf = [0; 3];
assert_eq!(Ok(0), reader.read(&mut [])); assert_eq!(Ok(0), reader.read(&mut []));
@ -233,7 +233,7 @@ mod test {
let mut writer = ChanWriter::new(tx); let mut writer = ChanWriter::new(tx);
writer.write_be_u32(42).unwrap(); writer.write_be_u32(42).unwrap();
let wanted = vec![0u8, 0u8, 0u8, 42u8]; let wanted = vec![0, 0, 0, 42];
let got = thread::scoped(move|| { rx.recv().unwrap() }).join(); let got = thread::scoped(move|| { rx.recv().unwrap() }).join();
assert_eq!(wanted, got); assert_eq!(wanted, got);

View file

@ -101,7 +101,7 @@ pub fn u64_to_le_bytes<T, F>(n: u64, size: uint, f: F) -> T where
let mut i = size; let mut i = size;
let mut n = n; let mut n = n;
while i > 0 { while i > 0 {
bytes.push((n & 255_u64) as u8); bytes.push((n & 255) as u8);
n >>= 8; n >>= 8;
i -= 1; i -= 1;
} }
@ -170,7 +170,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
panic!("index out of bounds"); panic!("index out of bounds");
} }
let mut buf = [0u8; 8]; let mut buf = [0; 8];
unsafe { unsafe {
let ptr = data.as_ptr().offset(start as int); let ptr = data.as_ptr().offset(start as int);
let out = buf.as_mut_ptr(); let out = buf.as_mut_ptr();
@ -522,8 +522,8 @@ mod bench {
({ ({
use super::u64_from_be_bytes; use super::u64_from_be_bytes;
let data = (0u8..$stride*100+$start_index).collect::<Vec<_>>(); let data = (0..$stride*100+$start_index).collect::<Vec<_>>();
let mut sum = 0u64; let mut sum = 0;
$b.iter(|| { $b.iter(|| {
let mut i = $start_index; let mut i = $start_index;
while i < data.len() { while i < data.len() {

View file

@ -1166,7 +1166,7 @@ mod test {
check!(w.write(msg)); check!(w.write(msg));
} }
let files = check!(readdir(dir)); let files = check!(readdir(dir));
let mut mem = [0u8; 4]; let mut mem = [0; 4];
for f in &files { for f in &files {
{ {
let n = f.filestem_str(); let n = f.filestem_str();
@ -1198,7 +1198,7 @@ mod test {
check!(File::create(&dir2.join("14"))); check!(File::create(&dir2.join("14")));
let mut files = check!(walk_dir(dir)); let mut files = check!(walk_dir(dir));
let mut cur = [0u8; 2]; let mut cur = [0; 2];
for f in files { for f in files {
let stem = f.filestem_str().unwrap(); let stem = f.filestem_str().unwrap();
let root = stem.as_bytes()[0] - b'0'; let root = stem.as_bytes()[0] - b'0';

View file

@ -670,7 +670,7 @@ pub trait Reader {
fn read_le_uint_n(&mut self, nbytes: uint) -> IoResult<u64> { fn read_le_uint_n(&mut self, nbytes: uint) -> IoResult<u64> {
assert!(nbytes > 0 && nbytes <= 8); assert!(nbytes > 0 && nbytes <= 8);
let mut val = 0u64; let mut val = 0;
let mut pos = 0; let mut pos = 0;
let mut i = nbytes; let mut i = nbytes;
while i > 0 { while i > 0 {
@ -694,7 +694,7 @@ pub trait Reader {
fn read_be_uint_n(&mut self, nbytes: uint) -> IoResult<u64> { fn read_be_uint_n(&mut self, nbytes: uint) -> IoResult<u64> {
assert!(nbytes > 0 && nbytes <= 8); assert!(nbytes > 0 && nbytes <= 8);
let mut val = 0u64; let mut val = 0;
let mut i = nbytes; let mut i = nbytes;
while i > 0 { while i > 0 {
i -= 1; i -= 1;
@ -1078,7 +1078,7 @@ pub trait Writer {
/// Write a single char, encoded as UTF-8. /// Write a single char, encoded as UTF-8.
#[inline] #[inline]
fn write_char(&mut self, c: char) -> IoResult<()> { fn write_char(&mut self, c: char) -> IoResult<()> {
let mut buf = [0u8; 4]; let mut buf = [0; 4];
let n = c.encode_utf8(&mut buf).unwrap_or(0); let n = c.encode_utf8(&mut buf).unwrap_or(0);
self.write_all(&buf[..n]) self.write_all(&buf[..n])
} }
@ -1896,7 +1896,7 @@ mod tests {
fn test_read_at_least() { fn test_read_at_least() {
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
vec![GoodBehavior(usize::MAX)]); vec![GoodBehavior(usize::MAX)]);
let buf = &mut [0u8; 5]; let buf = &mut [0; 5];
assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_at_least(1, buf).unwrap() >= 1);
assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least
assert!(r.read_at_least(0, buf).is_ok()); assert!(r.read_at_least(0, buf).is_ok());

View file

@ -198,7 +198,7 @@ impl<'a> Parser<'a> {
} }
fn read_number_impl(&mut self, radix: u8, max_digits: u32, upto: u32) -> Option<u32> { fn read_number_impl(&mut self, radix: u8, max_digits: u32, upto: u32) -> Option<u32> {
let mut r = 0u32; let mut r = 0;
let mut digit_count = 0; let mut digit_count = 0;
loop { loop {
match self.read_digit(radix) { match self.read_digit(radix) {
@ -226,7 +226,7 @@ impl<'a> Parser<'a> {
} }
fn read_ipv4_addr_impl(&mut self) -> Option<IpAddr> { fn read_ipv4_addr_impl(&mut self) -> Option<IpAddr> {
let mut bs = [0u8; 4]; let mut bs = [0; 4];
let mut i = 0; let mut i = 0;
while i < 4 { while i < 4 {
if i != 0 && self.read_given_char('.').is_none() { if i != 0 && self.read_given_char('.').is_none() {
@ -251,7 +251,7 @@ impl<'a> Parser<'a> {
fn read_ipv6_addr_impl(&mut self) -> Option<IpAddr> { fn read_ipv6_addr_impl(&mut self) -> Option<IpAddr> {
fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> IpAddr { fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> IpAddr {
assert!(head.len() + tail.len() <= 8); assert!(head.len() + tail.len() <= 8);
let mut gs = [0u16; 8]; let mut gs = [0; 8];
gs.clone_from_slice(head); gs.clone_from_slice(head);
gs[(8 - tail.len()) .. 8].clone_from_slice(tail); gs[(8 - tail.len()) .. 8].clone_from_slice(tail);
Ipv6Addr(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7]) Ipv6Addr(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7])
@ -294,7 +294,7 @@ impl<'a> Parser<'a> {
(i, false) (i, false)
} }
let mut head = [0u16; 8]; let mut head = [0; 8];
let (head_size, head_ipv4) = read_groups(self, &mut head, 8); let (head_size, head_ipv4) = read_groups(self, &mut head, 8);
if head_size == 8 { if head_size == 8 {
@ -313,7 +313,7 @@ impl<'a> Parser<'a> {
return None; return None;
} }
let mut tail = [0u16; 8]; let mut tail = [0; 8];
let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size); let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size);
Some(ipv6_addr_from_head_tail(&head[..head_size], &tail[..tail_size])) Some(ipv6_addr_from_head_tail(&head[..head_size], &tail[..tail_size]))
} }
@ -425,17 +425,17 @@ pub struct ParseError;
/// // The following lines are equivalent modulo possible "localhost" name resolution /// // The following lines are equivalent modulo possible "localhost" name resolution
/// // differences /// // differences
/// let tcp_s = TcpStream::connect(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 12345 }); /// let tcp_s = TcpStream::connect(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 12345 });
/// let tcp_s = TcpStream::connect((Ipv4Addr(127, 0, 0, 1), 12345u16)); /// let tcp_s = TcpStream::connect((Ipv4Addr(127, 0, 0, 1), 12345));
/// let tcp_s = TcpStream::connect(("127.0.0.1", 12345u16)); /// let tcp_s = TcpStream::connect(("127.0.0.1", 12345));
/// let tcp_s = TcpStream::connect(("localhost", 12345u16)); /// let tcp_s = TcpStream::connect(("localhost", 12345));
/// let tcp_s = TcpStream::connect("127.0.0.1:12345"); /// let tcp_s = TcpStream::connect("127.0.0.1:12345");
/// let tcp_s = TcpStream::connect("localhost:12345"); /// let tcp_s = TcpStream::connect("localhost:12345");
/// ///
/// // TcpListener::bind(), UdpSocket::bind() and UdpSocket::send_to() behave similarly /// // TcpListener::bind(), UdpSocket::bind() and UdpSocket::send_to() behave similarly
/// let tcp_l = TcpListener::bind("localhost:12345"); /// let tcp_l = TcpListener::bind("localhost:12345");
/// ///
/// let mut udp_s = UdpSocket::bind(("127.0.0.1", 23451u16)).unwrap(); /// let mut udp_s = UdpSocket::bind(("127.0.0.1", 23451)).unwrap();
/// udp_s.send_to([7u8, 7u8, 7u8].as_slice(), (Ipv4Addr(127, 0, 0, 1), 23451u16)); /// udp_s.send_to([7, 7, 7].as_slice(), (Ipv4Addr(127, 0, 0, 1), 23451));
/// } /// }
/// ``` /// ```
pub trait ToSocketAddr { pub trait ToSocketAddr {
@ -674,7 +674,7 @@ mod test {
#[test] #[test]
fn to_socket_addr_ipaddr_u16() { fn to_socket_addr_ipaddr_u16() {
let a = Ipv4Addr(77, 88, 21, 11); let a = Ipv4Addr(77, 88, 21, 11);
let p = 12345u16; let p = 12345;
let e = SocketAddr { ip: a, port: p }; let e = SocketAddr { ip: a, port: p };
assert_eq!(Ok(e), (a, p).to_socket_addr()); assert_eq!(Ok(e), (a, p).to_socket_addr());
assert_eq!(Ok(vec![e]), (a, p).to_socket_addr_all()); assert_eq!(Ok(vec![e]), (a, p).to_socket_addr_all());
@ -683,15 +683,15 @@ mod test {
#[test] #[test]
fn to_socket_addr_str_u16() { fn to_socket_addr_str_u16() {
let a = SocketAddr { ip: Ipv4Addr(77, 88, 21, 11), port: 24352 }; let a = SocketAddr { ip: Ipv4Addr(77, 88, 21, 11), port: 24352 };
assert_eq!(Ok(a), ("77.88.21.11", 24352u16).to_socket_addr()); assert_eq!(Ok(a), ("77.88.21.11", 24352).to_socket_addr());
assert_eq!(Ok(vec![a]), ("77.88.21.11", 24352u16).to_socket_addr_all()); assert_eq!(Ok(vec![a]), ("77.88.21.11", 24352).to_socket_addr_all());
let a = SocketAddr { ip: Ipv6Addr(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), port: 53 }; let a = SocketAddr { ip: Ipv6Addr(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), port: 53 };
assert_eq!(Ok(a), ("2a02:6b8:0:1::1", 53).to_socket_addr()); assert_eq!(Ok(a), ("2a02:6b8:0:1::1", 53).to_socket_addr());
assert_eq!(Ok(vec![a]), ("2a02:6b8:0:1::1", 53).to_socket_addr_all()); assert_eq!(Ok(vec![a]), ("2a02:6b8:0:1::1", 53).to_socket_addr_all());
let a = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 23924 }; let a = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 23924 };
assert!(("localhost", 23924u16).to_socket_addr_all().unwrap().contains(&a)); assert!(("localhost", 23924).to_socket_addr_all().unwrap().contains(&a));
} }
#[test] #[test]

View file

@ -1162,7 +1162,7 @@ mod test {
tx.send(TcpStream::connect(addr).unwrap()).unwrap(); tx.send(TcpStream::connect(addr).unwrap()).unwrap();
}); });
let _l = rx.recv().unwrap(); let _l = rx.recv().unwrap();
for i in 0i32..1001 { for i in 0..1001 {
match a.accept() { match a.accept() {
Ok(..) => break, Ok(..) => break,
Err(ref e) if e.kind == TimedOut => {} Err(ref e) if e.kind == TimedOut => {}
@ -1262,7 +1262,7 @@ mod test {
assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut); assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
s.set_timeout(Some(20)); s.set_timeout(Some(20));
for i in 0i32..1001 { for i in 0..1001 {
match s.write(&[0; 128 * 1024]) { match s.write(&[0; 128 * 1024]) {
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
Err(IoError { kind: TimedOut, .. }) => break, Err(IoError { kind: TimedOut, .. }) => break,
@ -1320,7 +1320,7 @@ mod test {
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_write_timeout(Some(20)); s.set_write_timeout(Some(20));
for i in 0i32..1001 { for i in 0..1001 {
match s.write(&[0; 128 * 1024]) { match s.write(&[0; 128 * 1024]) {
Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {},
Err(IoError { kind: TimedOut, .. }) => break, Err(IoError { kind: TimedOut, .. }) => break,

View file

@ -73,8 +73,8 @@ it is running in and assigns a port range based on it.
*/ */
fn base_port() -> u16 { fn base_port() -> u16 {
let base = 9600u16; let base = 9600;
let range = 1000u16; let range = 1000;
let bases = [ let bases = [
("32-opt", base + range * 1), ("32-opt", base + range * 1),

View file

@ -418,7 +418,7 @@ mod test {
#[test] #[test]
fn test_iter_reader() { fn test_iter_reader() {
let mut r = IterReader::new(0u8..8); let mut r = IterReader::new(0..8);
let mut buf = [0, 0, 0]; let mut buf = [0, 0, 0];
let len = r.read(&mut buf).unwrap(); let len = r.read(&mut buf).unwrap();
assert_eq!(len, 3); assert_eq!(len, 3);
@ -437,7 +437,7 @@ mod test {
#[test] #[test]
fn iter_reader_zero_length() { fn iter_reader_zero_length() {
let mut r = IterReader::new(0u8..8); let mut r = IterReader::new(0..8);
let mut buf = []; let mut buf = [];
assert_eq!(Ok(0), r.read(&mut buf)); assert_eq!(Ok(0), r.read(&mut buf));
} }

View file

@ -468,7 +468,7 @@ mod test {
let lengths = [0, 1, 2, 3, 4, 5, 6, 7, let lengths = [0, 1, 2, 3, 4, 5, 6, 7,
80, 81, 82, 83, 84, 85, 86, 87]; 80, 81, 82, 83, 84, 85, 86, 87];
for &n in &lengths { for &n in &lengths {
let mut v = repeat(0u8).take(n).collect::<Vec<_>>(); let mut v = repeat(0).take(n).collect::<Vec<_>>();
r.fill_bytes(&mut v); r.fill_bytes(&mut v);
// use this to get nicer error messages. // use this to get nicer error messages.

View file

@ -80,13 +80,13 @@ mod imp {
} }
fn getrandom_next_u32() -> u32 { fn getrandom_next_u32() -> u32 {
let mut buf: [u8; 4] = [0u8; 4]; let mut buf: [u8; 4] = [0; 4];
getrandom_fill_bytes(&mut buf); getrandom_fill_bytes(&mut buf);
unsafe { mem::transmute::<[u8; 4], u32>(buf) } unsafe { mem::transmute::<[u8; 4], u32>(buf) }
} }
fn getrandom_next_u64() -> u64 { fn getrandom_next_u64() -> u64 {
let mut buf: [u8; 8] = [0u8; 8]; let mut buf: [u8; 8] = [0; 8];
getrandom_fill_bytes(&mut buf); getrandom_fill_bytes(&mut buf);
unsafe { mem::transmute::<[u8; 8], u64>(buf) } unsafe { mem::transmute::<[u8; 8], u64>(buf) }
} }
@ -231,12 +231,12 @@ mod imp {
impl Rng for OsRng { impl Rng for OsRng {
fn next_u32(&mut self) -> u32 { fn next_u32(&mut self) -> u32 {
let mut v = [0u8; 4]; let mut v = [0; 4];
self.fill_bytes(&mut v); self.fill_bytes(&mut v);
unsafe { mem::transmute(v) } unsafe { mem::transmute(v) }
} }
fn next_u64(&mut self) -> u64 { fn next_u64(&mut self) -> u64 {
let mut v = [0u8; 8]; let mut v = [0; 8];
self.fill_bytes(&mut v); self.fill_bytes(&mut v);
unsafe { mem::transmute(v) } unsafe { mem::transmute(v) }
} }
@ -318,12 +318,12 @@ mod imp {
impl Rng for OsRng { impl Rng for OsRng {
fn next_u32(&mut self) -> u32 { fn next_u32(&mut self) -> u32 {
let mut v = [0u8; 4]; let mut v = [0; 4];
self.fill_bytes(&mut v); self.fill_bytes(&mut v);
unsafe { mem::transmute(v) } unsafe { mem::transmute(v) }
} }
fn next_u64(&mut self) -> u64 { fn next_u64(&mut self) -> u64 {
let mut v = [0u8; 8]; let mut v = [0; 8];
self.fill_bytes(&mut v); self.fill_bytes(&mut v);
unsafe { mem::transmute(v) } unsafe { mem::transmute(v) }
} }
@ -366,7 +366,7 @@ mod test {
r.next_u32(); r.next_u32();
r.next_u64(); r.next_u64();
let mut v = [0u8; 1000]; let mut v = [0; 1000];
r.fill_bytes(&mut v); r.fill_bytes(&mut v);
} }
@ -386,7 +386,7 @@ mod test {
// as possible (XXX: is this a good test?) // as possible (XXX: is this a good test?)
let mut r = OsRng::new().unwrap(); let mut r = OsRng::new().unwrap();
thread::yield_now(); thread::yield_now();
let mut v = [0u8; 1000]; let mut v = [0; 1000];
for _ in 0..100 { for _ in 0..100 {
r.next_u32(); r.next_u32();

View file

@ -84,28 +84,28 @@ mod test {
#[test] #[test]
fn test_reader_rng_u64() { fn test_reader_rng_u64() {
// transmute from the target to avoid endianness concerns. // transmute from the target to avoid endianness concerns.
let v = vec![0u8, 0, 0, 0, 0, 0, 0, 1, let v = vec![0, 0, 0, 0, 0, 0, 0, 1,
0 , 0, 0, 0, 0, 0, 0, 2, 0 , 0, 0, 0, 0, 0, 0, 2,
0, 0, 0, 0, 0, 0, 0, 3]; 0, 0, 0, 0, 0, 0, 0, 3];
let mut rng = ReaderRng::new(MemReader::new(v)); let mut rng = ReaderRng::new(MemReader::new(v));
assert_eq!(rng.next_u64(), 1_u64.to_be()); assert_eq!(rng.next_u64(), 1.to_be());
assert_eq!(rng.next_u64(), 2_u64.to_be()); assert_eq!(rng.next_u64(), 2.to_be());
assert_eq!(rng.next_u64(), 3_u64.to_be()); assert_eq!(rng.next_u64(), 3.to_be());
} }
#[test] #[test]
fn test_reader_rng_u32() { fn test_reader_rng_u32() {
let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]; let v = vec![0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3];
let mut rng = ReaderRng::new(MemReader::new(v)); let mut rng = ReaderRng::new(MemReader::new(v));
assert_eq!(rng.next_u32(), 1_u32.to_be()); assert_eq!(rng.next_u32(), 1.to_be());
assert_eq!(rng.next_u32(), 2_u32.to_be()); assert_eq!(rng.next_u32(), 2.to_be());
assert_eq!(rng.next_u32(), 3_u32.to_be()); assert_eq!(rng.next_u32(), 3.to_be());
} }
#[test] #[test]
fn test_reader_rng_fill_bytes() { fn test_reader_rng_fill_bytes() {
let v = [1u8, 2, 3, 4, 5, 6, 7, 8]; let v = [1, 2, 3, 4, 5, 6, 7, 8];
let mut w = [0u8; 8]; let mut w = [0; 8];
let mut rng = ReaderRng::new(MemReader::new(v.to_vec())); let mut rng = ReaderRng::new(MemReader::new(v.to_vec()));
rng.fill_bytes(&mut w); rng.fill_bytes(&mut w);
@ -117,7 +117,7 @@ mod test {
#[should_fail] #[should_fail]
fn test_reader_rng_insufficient_bytes() { fn test_reader_rng_insufficient_bytes() {
let mut rng = ReaderRng::new(MemReader::new(vec!())); let mut rng = ReaderRng::new(MemReader::new(vec!()));
let mut v = [0u8; 3]; let mut v = [0; 3];
rng.fill_bytes(&mut v); rng.fill_bytes(&mut v);
} }
} }

View file

@ -139,7 +139,7 @@ pub fn abort(args: fmt::Arguments) -> ! {
} }
// Convert the arguments into a stack-allocated string // Convert the arguments into a stack-allocated string
let mut msg = [0u8; 512]; let mut msg = [0; 512];
let mut w = BufWriter { buf: &mut msg, pos: 0 }; let mut w = BufWriter { buf: &mut msg, pos: 0 };
let _ = write!(&mut w, "{}", args); let _ = write!(&mut w, "{}", args);
let msg = str::from_utf8(&w.buf[..w.pos]).unwrap_or("aborted"); let msg = str::from_utf8(&w.buf[..w.pos]).unwrap_or("aborted");

View file

@ -714,7 +714,7 @@ pub fn is_code_point_boundary(slice: &Wtf8, index: uint) -> bool {
if index == slice.len() { return true; } if index == slice.len() { return true; }
match slice.bytes.get(index) { match slice.bytes.get(index) {
None => false, None => false,
Some(&b) => b < 128u8 || b >= 192u8, Some(&b) => b < 128 || b >= 192,
} }
} }
@ -776,7 +776,7 @@ impl<'a> Iterator for EncodeWide<'a> {
return Some(tmp); return Some(tmp);
} }
let mut buf = [0u16; 2]; let mut buf = [0; 2];
self.code_points.next().map(|code_point| { self.code_points.next().map(|code_point| {
let n = encode_utf16_raw(code_point.value, &mut buf) let n = encode_utf16_raw(code_point.value, &mut buf)
.unwrap_or(0); .unwrap_or(0);

View file

@ -389,7 +389,7 @@ mod tests {
let mut writer = FileDesc::new(writer, true); let mut writer = FileDesc::new(writer, true);
writer.write(b"test").ok().unwrap(); writer.write(b"test").ok().unwrap();
let mut buf = [0u8; 4]; let mut buf = [0; 4];
match reader.read(&mut buf) { match reader.read(&mut buf) {
Ok(4) => { Ok(4) => {
assert_eq!(buf[0], 't' as u8); assert_eq!(buf[0], 't' as u8);

View file

@ -901,7 +901,7 @@ mod test {
assert!(e.is::<T>()); assert!(e.is::<T>());
let any = e.downcast::<T>().ok().unwrap(); let any = e.downcast::<T>().ok().unwrap();
assert!(any.is::<u16>()); assert!(any.is::<u16>());
assert_eq!(*any.downcast::<u16>().ok().unwrap(), 413u16); assert_eq!(*any.downcast::<u16>().ok().unwrap(), 413);
} }
Ok(()) => panic!() Ok(()) => panic!()
} }

View file

@ -53,7 +53,7 @@
//! assert!(b == c); //! assert!(b == c);
//! //!
//! let d : (u32, f32) = Default::default(); //! let d : (u32, f32) = Default::default();
//! assert_eq!(d, (0u32, 0.0f32)); //! assert_eq!(d, (0, 0.0f32));
//! ``` //! ```
#![doc(primitive = "tuple")] #![doc(primitive = "tuple")]

View file

@ -159,10 +159,10 @@ pub fn int_ty_to_string(t: IntTy, val: Option<i64>) -> String {
pub fn int_ty_max(t: IntTy) -> u64 { pub fn int_ty_max(t: IntTy) -> u64 {
match t { match t {
TyI8 => 0x80u64, TyI8 => 0x80,
TyI16 => 0x8000u64, TyI16 => 0x8000,
TyIs(_) | TyI32 => 0x80000000u64, // actually ni about TyIs TyIs(_) | TyI32 => 0x80000000, // actually ni about TyIs
TyI64 => 0x8000000000000000u64 TyI64 => 0x8000000000000000
} }
} }
@ -185,10 +185,10 @@ pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String {
pub fn uint_ty_max(t: UintTy) -> u64 { pub fn uint_ty_max(t: UintTy) -> u64 {
match t { match t {
TyU8 => 0xffu64, TyU8 => 0xff,
TyU16 => 0xffffu64, TyU16 => 0xffff,
TyUs(_) | TyU32 => 0xffffffffu64, // actually ni about TyUs TyUs(_) | TyU32 => 0xffffffff, // actually ni about TyUs
TyU64 => 0xffffffffffffffffu64 TyU64 => 0xffffffffffffffff
} }
} }

View file

@ -154,23 +154,23 @@ pub mod color {
/// Number for a terminal color /// Number for a terminal color
pub type Color = u16; pub type Color = u16;
pub const BLACK: Color = 0u16; pub const BLACK: Color = 0;
pub const RED: Color = 1u16; pub const RED: Color = 1;
pub const GREEN: Color = 2u16; pub const GREEN: Color = 2;
pub const YELLOW: Color = 3u16; pub const YELLOW: Color = 3;
pub const BLUE: Color = 4u16; pub const BLUE: Color = 4;
pub const MAGENTA: Color = 5u16; pub const MAGENTA: Color = 5;
pub const CYAN: Color = 6u16; pub const CYAN: Color = 6;
pub const WHITE: Color = 7u16; pub const WHITE: Color = 7;
pub const BRIGHT_BLACK: Color = 8u16; pub const BRIGHT_BLACK: Color = 8;
pub const BRIGHT_RED: Color = 9u16; pub const BRIGHT_RED: Color = 9;
pub const BRIGHT_GREEN: Color = 10u16; pub const BRIGHT_GREEN: Color = 10;
pub const BRIGHT_YELLOW: Color = 11u16; pub const BRIGHT_YELLOW: Color = 11;
pub const BRIGHT_BLUE: Color = 12u16; pub const BRIGHT_BLUE: Color = 12;
pub const BRIGHT_MAGENTA: Color = 13u16; pub const BRIGHT_MAGENTA: Color = 13;
pub const BRIGHT_CYAN: Color = 14u16; pub const BRIGHT_CYAN: Color = 14;
pub const BRIGHT_WHITE: Color = 15u16; pub const BRIGHT_WHITE: Color = 15;
} }
/// Terminal attributes /// Terminal attributes

View file

@ -128,7 +128,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
// if c is 0, use 0200 (128) for ncurses compatibility // if c is 0, use 0200 (128) for ncurses compatibility
Number(c) => { Number(c) => {
output.push(if c == 0 { output.push(if c == 0 {
128u8 128
} else { } else {
c as u8 c as u8
}) })
@ -647,7 +647,7 @@ mod test {
#[test] #[test]
fn test_comparison_ops() { fn test_comparison_ops() {
let v = [('<', [1u8, 0u8, 0u8]), ('=', [0u8, 1u8, 0u8]), ('>', [0u8, 0u8, 1u8])]; let v = [('<', [1, 0, 0]), ('=', [0, 1, 0]), ('>', [0, 0, 1])];
for &(op, bs) in &v { for &(op, bs) in &v {
let s = format!("%{{1}}%{{2}}%{}%d", op); let s = format!("%{{1}}%{{2}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new()); let res = expand(s.as_bytes(), &[], &mut Variables::new());

View file

@ -1024,7 +1024,7 @@ impl Bencher {
pub fn iter<T, F>(&mut self, mut inner: F) where F: FnMut() -> T { pub fn iter<T, F>(&mut self, mut inner: F) where F: FnMut() -> T {
self.dur = Duration::span(|| { self.dur = Duration::span(|| {
let k = self.iterations; let k = self.iterations;
for _ in 0u64..k { for _ in 0..k {
black_box(inner()); black_box(inner());
} }
}); });
@ -1050,7 +1050,7 @@ impl Bencher {
// This is a more statistics-driven benchmark algorithm // This is a more statistics-driven benchmark algorithm
pub fn auto_bench<F>(&mut self, mut f: F) -> stats::Summary<f64> where F: FnMut(&mut Bencher) { pub fn auto_bench<F>(&mut self, mut f: F) -> stats::Summary<f64> where F: FnMut(&mut Bencher) {
// Initial bench run to get ballpark figure. // Initial bench run to get ballpark figure.
let mut n = 1_u64; let mut n = 1;
self.bench_n(n, |x| f(x)); self.bench_n(n, |x| f(x));
// Try to estimate iter count for 1ms falling back to 1m // Try to estimate iter count for 1ms falling back to 1m

View file

@ -525,7 +525,7 @@ impl<I> Iterator for Utf16Encoder<I> where I: Iterator<Item=char> {
return Some(tmp); return Some(tmp);
} }
let mut buf = [0u16; 2]; let mut buf = [0; 2];
self.chars.next().map(|ch| { self.chars.next().map(|ch| {
let n = CharExt::encode_utf16(ch, &mut buf).unwrap_or(0); let n = CharExt::encode_utf16(ch, &mut buf).unwrap_or(0);
if n == 2 { self.extra = buf[1]; } if n == 2 { self.extra = buf[1]; }

View file

@ -16,7 +16,7 @@ pub mod kitties {
} }
impl cat { impl cat {
pub fn speak(&mut self) { self.meows += 1_usize; } pub fn speak(&mut self) { self.meows += 1; }
pub fn meow_count(&mut self) -> uint { self.meows } pub fn meow_count(&mut self) -> uint { self.meows }
} }

View file

@ -34,8 +34,8 @@ pub mod kitties {
impl cat { impl cat {
pub fn meow(&mut self) { pub fn meow(&mut self) {
println!("Meow"); println!("Meow");
self.meows += 1_usize; self.meows += 1;
if self.meows % 5_usize == 0_usize { if self.meows % 5 == 0 {
self.how_hungry += 1; self.how_hungry += 1;
} }
} }

View file

@ -26,8 +26,8 @@ pub mod kitty {
impl cat { impl cat {
fn meow(&mut self) { fn meow(&mut self) {
println!("Meow"); println!("Meow");
self.meows += 1_usize; self.meows += 1;
if self.meows % 5_usize == 0_usize { if self.meows % 5 == 0 {
self.how_hungry += 1; self.how_hungry += 1;
} }
} }

View file

@ -20,7 +20,7 @@ impl uint_helpers for uint {
let mut i = *self; let mut i = *self;
while i < v { while i < v {
f(i); f(i);
i += 1_usize; i += 1;
} }
} }
} }

View file

@ -12,10 +12,10 @@
#[inline] #[inline]
pub fn iter<T, F>(v: &[T], mut f: F) where F: FnMut(&T) { pub fn iter<T, F>(v: &[T], mut f: F) where F: FnMut(&T) {
let mut i = 0_usize; let mut i = 0;
let n = v.len(); let n = v.len();
while i < n { while i < n {
f(&v[i]); f(&v[i]);
i += 1_usize; i += 1;
} }
} }

View file

@ -13,10 +13,10 @@
// same as cci_iter_lib, more-or-less, but not marked inline // same as cci_iter_lib, more-or-less, but not marked inline
pub fn iter<F>(v: Vec<uint> , mut f: F) where F: FnMut(uint) { pub fn iter<F>(v: Vec<uint> , mut f: F) where F: FnMut(uint) {
let mut i = 0_usize; let mut i = 0;
let n = v.len(); let n = v.len();
while i < n { while i < n {
f(v[i]); f(v[i]);
i += 1_usize; i += 1;
} }
} }

View file

@ -11,5 +11,5 @@
#![crate_type = "dylib"] #![crate_type = "dylib"]
#[macro_export] #[macro_export]
macro_rules! reexported { macro_rules! reexported {
() => ( 3_usize ) () => ( 3 )
} }

View file

@ -47,7 +47,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}; };
let mut text = &*text; let mut text = &*text;
let mut total = 0_usize; let mut total = 0;
while !text.is_empty() { while !text.is_empty() {
match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) { match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
Some(&(rn, val)) => { Some(&(rn, val)) => {

View file

@ -14,9 +14,9 @@ use std::ops::Add;
#[inline] #[inline]
pub fn has_closures() -> uint { pub fn has_closures() -> uint {
let x = 1_usize; let x = 1;
let mut f = move || x; let mut f = move || x;
let y = 1_usize; let y = 1;
let g = || y; let g = || y;
f() + g() f() + g()
} }

View file

@ -49,7 +49,7 @@ impl Noise2DContext {
*x = random_gradient(&mut rng); *x = random_gradient(&mut rng);
} }
let mut permutations = [0i32; 256]; let mut permutations = [0; 256];
for (i, x) in permutations.iter_mut().enumerate() { for (i, x) in permutations.iter_mut().enumerate() {
*x = i as i32; *x = i as i32;
} }

View file

@ -145,7 +145,7 @@ fn creature(
to_rendezvous: Sender<CreatureInfo>, to_rendezvous: Sender<CreatureInfo>,
to_rendezvous_log: Sender<String> to_rendezvous_log: Sender<String>
) { ) {
let mut creatures_met = 0i32; let mut creatures_met = 0;
let mut evil_clones_met = 0; let mut evil_clones_met = 0;
let mut rendezvous = from_rendezvous.iter(); let mut rendezvous = from_rendezvous.iter();

View file

@ -91,7 +91,7 @@ impl Perm {
} }
fn get(&mut self, mut idx: i32) -> P { fn get(&mut self, mut idx: i32) -> P {
let mut pp = [0u8; 16]; let mut pp = [0; 16];
self.permcount = idx as u32; self.permcount = idx as u32;
for (i, place) in self.perm.p.iter_mut().enumerate() { for (i, place) in self.perm.p.iter_mut().enumerate() {
*place = i as i32 + 1; *place = i as i32 + 1;
@ -183,7 +183,7 @@ fn main() {
let n = std::env::args() let n = std::env::args()
.nth(1) .nth(1)
.and_then(|arg| arg.parse().ok()) .and_then(|arg| arg.parse().ok())
.unwrap_or(2i32); .unwrap_or(2);
let (checksum, maxflips) = fannkuch(n); let (checksum, maxflips) = fannkuch(n);
println!("{}\nPfannkuchen({}) = {}", checksum, n, maxflips); println!("{}\nPfannkuchen({}) = {}", checksum, n, maxflips);

View file

@ -121,7 +121,7 @@ impl<'a, W: Writer> RepeatFasta<'a, W> {
fn make(&mut self, n: usize) -> IoResult<()> { fn make(&mut self, n: usize) -> IoResult<()> {
let alu_len = self.alu.len(); let alu_len = self.alu.len();
let mut buf = repeat(0u8).take(alu_len + LINE_LEN).collect::<Vec<_>>(); let mut buf = repeat(0).take(alu_len + LINE_LEN).collect::<Vec<_>>();
let alu: &[u8] = self.alu.as_bytes(); let alu: &[u8] = self.alu.as_bytes();
copy_memory(&mut buf, alu); copy_memory(&mut buf, alu);

View file

@ -89,7 +89,7 @@ fn make_fasta<W: Writer, I: Iterator<Item=u8>>(
-> std::old_io::IoResult<()> -> std::old_io::IoResult<()>
{ {
try!(wr.write(header.as_bytes())); try!(wr.write(header.as_bytes()));
let mut line = [0u8; LINE_LENGTH + 1]; let mut line = [0; LINE_LENGTH + 1];
while n > 0 { while n > 0 {
let nb = min(LINE_LENGTH, n); let nb = min(LINE_LENGTH, n);
for i in 0..nb { for i in 0..nb {

View file

@ -78,11 +78,11 @@ impl Code {
} }
fn rotate(&self, c: u8, frame: usize) -> Code { fn rotate(&self, c: u8, frame: usize) -> Code {
Code(self.push_char(c).hash() & ((1u64 << (2 * frame)) - 1)) Code(self.push_char(c).hash() & ((1 << (2 * frame)) - 1))
} }
fn pack(string: &str) -> Code { fn pack(string: &str) -> Code {
string.bytes().fold(Code(0u64), |a, b| a.push_char(b)) string.bytes().fold(Code(0), |a, b| a.push_char(b))
} }
fn unpack(&self, frame: usize) -> String { fn unpack(&self, frame: usize) -> String {

View file

@ -169,7 +169,7 @@ fn make_masks() -> Vec<Vec<Vec<u64> > > {
.map(|(id, p)| transform(p, id != 3)) .map(|(id, p)| transform(p, id != 3))
.collect(); .collect();
(0i32..50).map(|yx| { (0..50).map(|yx| {
transforms.iter().enumerate().map(|(id, t)| { transforms.iter().enumerate().map(|(id, t)| {
t.iter().filter_map(|p| mask(yx / 5, yx % 5, id, p)).collect() t.iter().filter_map(|p| mask(yx / 5, yx % 5, id, p)).collect()
}).collect() }).collect()
@ -211,7 +211,7 @@ fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) {
// Gets the identifier of a mask. // Gets the identifier of a mask.
fn get_id(m: u64) -> u8 { fn get_id(m: u64) -> u8 {
for id in 0u8..10 { for id in 0..10 {
if m & (1 << (id + 50) as usize) != 0 {return id;} if m & (1 << (id + 50) as usize) != 0 {return id;}
} }
panic!("{:016x} does not have a valid identifier", m); panic!("{:016x} does not have a valid identifier", m);

View file

@ -60,7 +60,7 @@ impl Sudoku {
reader.read_line(&mut s).unwrap(); reader.read_line(&mut s).unwrap();
assert_eq!(s, "9,9\n"); assert_eq!(s, "9,9\n");
let mut g = repeat(vec![0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8]) let mut g = repeat(vec![0, 0, 0, 0, 0, 0, 0, 0, 0])
.take(10).collect::<Vec<_>>(); .take(10).collect::<Vec<_>>();
for line in reader.lines() { for line in reader.lines() {
let line = line.unwrap(); let line = line.unwrap();
@ -94,10 +94,10 @@ impl Sudoku {
// solve sudoku grid // solve sudoku grid
pub fn solve(&mut self) { pub fn solve(&mut self) {
let mut work: Vec<(u8, u8)> = Vec::new(); /* queue of uncolored fields */ let mut work: Vec<(u8, u8)> = Vec::new(); /* queue of uncolored fields */
for row in 0u8..9u8 { for row in 0..9 {
for col in 0u8..9u8 { for col in 0..9 {
let color = self.grid[row as usize][col as usize]; let color = self.grid[row as usize][col as usize];
if color == 0u8 { if color == 0 {
work.push((row, col)); work.push((row, col));
} }
} }
@ -122,7 +122,7 @@ impl Sudoku {
} }
fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool { fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool {
if start_color < 10u8 { if start_color < 10 {
// colors not yet used // colors not yet used
let mut avail: Box<_> = box Colors::new(start_color); let mut avail: Box<_> = box Colors::new(start_color);
@ -132,15 +132,15 @@ impl Sudoku {
// find first remaining color that is available // find first remaining color that is available
let next = avail.next(); let next = avail.next();
self.grid[row as usize][col as usize] = next; self.grid[row as usize][col as usize] = next;
return 0u8 != next; return 0 != next;
} }
self.grid[row as usize][col as usize] = 0u8; self.grid[row as usize][col as usize] = 0;
return false; return false;
} }
// find colors available in neighbourhood of (row, col) // find colors available in neighbourhood of (row, col)
fn drop_colors(&mut self, avail: &mut Colors, row: u8, col: u8) { fn drop_colors(&mut self, avail: &mut Colors, row: u8, col: u8) {
for idx in 0u8..9u8 { for idx in 0..9 {
/* check same column fields */ /* check same column fields */
avail.remove(self.grid[idx as usize][col as usize]); avail.remove(self.grid[idx as usize][col as usize]);
/* check same row fields */ /* check same row fields */
@ -148,10 +148,10 @@ impl Sudoku {
} }
// check same block fields // check same block fields
let row0 = (row / 3u8) * 3u8; let row0 = (row / 3) * 3;
let col0 = (col / 3u8) * 3u8; let col0 = (col / 3) * 3;
for alt_row in row0..row0 + 3u8 { for alt_row in row0..row0 + 3 {
for alt_col in col0..col0 + 3u8 { for alt_col in col0..col0 + 3 {
avail.remove(self.grid[alt_row as usize][alt_col as usize]); avail.remove(self.grid[alt_row as usize][alt_col as usize]);
} }
} }
@ -161,29 +161,29 @@ impl Sudoku {
// Stores available colors as simple bitfield, bit 0 is always unset // Stores available colors as simple bitfield, bit 0 is always unset
struct Colors(u16); struct Colors(u16);
static HEADS: u16 = (1u16 << 10) - 1; /* bits 9..0 */ static HEADS: u16 = (1 << 10) - 1; /* bits 9..0 */
impl Colors { impl Colors {
fn new(start_color: u8) -> Colors { fn new(start_color: u8) -> Colors {
// Sets bits 9..start_color // Sets bits 9..start_color
let tails = !0u16 << start_color as usize; let tails = !0 << start_color as usize;
return Colors(HEADS & tails); return Colors(HEADS & tails);
} }
fn next(&self) -> u8 { fn next(&self) -> u8 {
let Colors(c) = *self; let Colors(c) = *self;
let val = c & HEADS; let val = c & HEADS;
if 0u16 == val { if 0 == val {
return 0u8; return 0;
} else { } else {
return val.trailing_zeros() as u8 return val.trailing_zeros() as u8
} }
} }
fn remove(&mut self, color: u8) { fn remove(&mut self, color: u8) {
if color != 0u8 { if color != 0 {
let Colors(val) = *self; let Colors(val) = *self;
let mask = !(1u16 << color as usize); let mask = !(1 << color as usize);
*self = Colors(val & mask); *self = Colors(val & mask);
} }
} }
@ -191,57 +191,57 @@ impl Colors {
static DEFAULT_SUDOKU: [[u8;9];9] = [ static DEFAULT_SUDOKU: [[u8;9];9] = [
/* 0 1 2 3 4 5 6 7 8 */ /* 0 1 2 3 4 5 6 7 8 */
/* 0 */ [0u8, 4u8, 0u8, 6u8, 0u8, 0u8, 0u8, 3u8, 2u8], /* 0 */ [0, 4, 0, 6, 0, 0, 0, 3, 2],
/* 1 */ [0u8, 0u8, 8u8, 0u8, 2u8, 0u8, 0u8, 0u8, 0u8], /* 1 */ [0, 0, 8, 0, 2, 0, 0, 0, 0],
/* 2 */ [7u8, 0u8, 0u8, 8u8, 0u8, 0u8, 0u8, 0u8, 0u8], /* 2 */ [7, 0, 0, 8, 0, 0, 0, 0, 0],
/* 3 */ [0u8, 0u8, 0u8, 5u8, 0u8, 0u8, 0u8, 0u8, 0u8], /* 3 */ [0, 0, 0, 5, 0, 0, 0, 0, 0],
/* 4 */ [0u8, 5u8, 0u8, 0u8, 0u8, 3u8, 6u8, 0u8, 0u8], /* 4 */ [0, 5, 0, 0, 0, 3, 6, 0, 0],
/* 5 */ [6u8, 8u8, 0u8, 0u8, 0u8, 0u8, 0u8, 9u8, 0u8], /* 5 */ [6, 8, 0, 0, 0, 0, 0, 9, 0],
/* 6 */ [0u8, 9u8, 5u8, 0u8, 0u8, 6u8, 0u8, 7u8, 0u8], /* 6 */ [0, 9, 5, 0, 0, 6, 0, 7, 0],
/* 7 */ [0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 6u8, 0u8], /* 7 */ [0, 0, 0, 0, 4, 0, 0, 6, 0],
/* 8 */ [4u8, 0u8, 0u8, 0u8, 0u8, 7u8, 2u8, 0u8, 3u8] /* 8 */ [4, 0, 0, 0, 0, 7, 2, 0, 3]
]; ];
#[cfg(test)] #[cfg(test)]
static DEFAULT_SOLUTION: [[u8;9];9] = [ static DEFAULT_SOLUTION: [[u8;9];9] = [
/* 0 1 2 3 4 5 6 7 8 */ /* 0 1 2 3 4 5 6 7 8 */
/* 0 */ [1u8, 4u8, 9u8, 6u8, 7u8, 5u8, 8u8, 3u8, 2u8], /* 0 */ [1, 4, 9, 6, 7, 5, 8, 3, 2],
/* 1 */ [5u8, 3u8, 8u8, 1u8, 2u8, 9u8, 7u8, 4u8, 6u8], /* 1 */ [5, 3, 8, 1, 2, 9, 7, 4, 6],
/* 2 */ [7u8, 2u8, 6u8, 8u8, 3u8, 4u8, 1u8, 5u8, 9u8], /* 2 */ [7, 2, 6, 8, 3, 4, 1, 5, 9],
/* 3 */ [9u8, 1u8, 4u8, 5u8, 6u8, 8u8, 3u8, 2u8, 7u8], /* 3 */ [9, 1, 4, 5, 6, 8, 3, 2, 7],
/* 4 */ [2u8, 5u8, 7u8, 4u8, 9u8, 3u8, 6u8, 1u8, 8u8], /* 4 */ [2, 5, 7, 4, 9, 3, 6, 1, 8],
/* 5 */ [6u8, 8u8, 3u8, 7u8, 1u8, 2u8, 5u8, 9u8, 4u8], /* 5 */ [6, 8, 3, 7, 1, 2, 5, 9, 4],
/* 6 */ [3u8, 9u8, 5u8, 2u8, 8u8, 6u8, 4u8, 7u8, 1u8], /* 6 */ [3, 9, 5, 2, 8, 6, 4, 7, 1],
/* 7 */ [8u8, 7u8, 2u8, 3u8, 4u8, 1u8, 9u8, 6u8, 5u8], /* 7 */ [8, 7, 2, 3, 4, 1, 9, 6, 5],
/* 8 */ [4u8, 6u8, 1u8, 9u8, 5u8, 7u8, 2u8, 8u8, 3u8] /* 8 */ [4, 6, 1, 9, 5, 7, 2, 8, 3]
]; ];
#[test] #[test]
fn colors_new_works() { fn colors_new_works() {
assert_eq!(*Colors::new(1), 1022u16); assert_eq!(*Colors::new(1), 1022);
assert_eq!(*Colors::new(2), 1020u16); assert_eq!(*Colors::new(2), 1020);
assert_eq!(*Colors::new(3), 1016u16); assert_eq!(*Colors::new(3), 1016);
assert_eq!(*Colors::new(4), 1008u16); assert_eq!(*Colors::new(4), 1008);
assert_eq!(*Colors::new(5), 992u16); assert_eq!(*Colors::new(5), 992);
assert_eq!(*Colors::new(6), 960u16); assert_eq!(*Colors::new(6), 960);
assert_eq!(*Colors::new(7), 896u16); assert_eq!(*Colors::new(7), 896);
assert_eq!(*Colors::new(8), 768u16); assert_eq!(*Colors::new(8), 768);
assert_eq!(*Colors::new(9), 512u16); assert_eq!(*Colors::new(9), 512);
} }
#[test] #[test]
fn colors_next_works() { fn colors_next_works() {
assert_eq!(Colors(0).next(), 0u8); assert_eq!(Colors(0).next(), 0);
assert_eq!(Colors(2).next(), 1u8); assert_eq!(Colors(2).next(), 1);
assert_eq!(Colors(4).next(), 2u8); assert_eq!(Colors(4).next(), 2);
assert_eq!(Colors(8).next(), 3u8); assert_eq!(Colors(8).next(), 3);
assert_eq!(Colors(16).next(), 4u8); assert_eq!(Colors(16).next(), 4);
assert_eq!(Colors(32).next(), 5u8); assert_eq!(Colors(32).next(), 5);
assert_eq!(Colors(64).next(), 6u8); assert_eq!(Colors(64).next(), 6);
assert_eq!(Colors(128).next(), 7u8); assert_eq!(Colors(128).next(), 7);
assert_eq!(Colors(256).next(), 8u8); assert_eq!(Colors(256).next(), 8);
assert_eq!(Colors(512).next(), 9u8); assert_eq!(Colors(512).next(), 9);
assert_eq!(Colors(1024).next(), 0u8); assert_eq!(Colors(1024).next(), 0);
} }
#[test] #[test]
@ -253,7 +253,7 @@ fn colors_remove_works() {
colors.remove(1); colors.remove(1);
// THEN // THEN
assert_eq!(colors.next(), 2u8); assert_eq!(colors.next(), 2);
} }
#[test] #[test]

View file

@ -15,6 +15,6 @@ pub use use_from_trait_xc::Trait;
fn main() { fn main() {
match () { match () {
Trait { x: 42_usize } => () //~ ERROR use of trait `Trait` in a struct pattern Trait { x: 42 } => () //~ ERROR use of trait `Trait` in a struct pattern
} }
} }

View file

@ -9,14 +9,14 @@
// except according to those terms. // except according to those terms.
fn main() { fn main() {
let _x: i32 = [1i32, 2, 3]; let _x: i32 = [1, 2, 3];
//~^ ERROR mismatched types //~^ ERROR mismatched types
//~| expected `i32` //~| expected `i32`
//~| found `[i32; 3]` //~| found `[i32; 3]`
//~| expected i32 //~| expected i32
//~| found array of 3 elements //~| found array of 3 elements
let x: &[i32] = &[1i32, 2, 3]; let x: &[i32] = &[1, 2, 3];
let _y: &i32 = x; let _y: &i32 = x;
//~^ ERROR mismatched types //~^ ERROR mismatched types
//~| expected `&i32` //~| expected `&i32`

View file

@ -20,8 +20,8 @@ pub fn main() {
let x: isize; let x: isize;
let y: isize; let y: isize;
unsafe { unsafe {
asm!("mov $1, $0" : "=r"(x) : "=r"(5_usize)); //~ ERROR operand constraint contains '=' asm!("mov $1, $0" : "=r"(x) : "=r"(5)); //~ ERROR operand constraint contains '='
asm!("mov $1, $0" : "=r"(y) : "+r"(5_usize)); //~ ERROR operand constraint contains '+' asm!("mov $1, $0" : "=r"(y) : "+r"(5)); //~ ERROR operand constraint contains '+'
} }
foo(x); foo(x);
foo(y); foo(y);

View file

@ -21,7 +21,7 @@ pub fn main() {
x = 1; //~ NOTE prior assignment occurs here x = 1; //~ NOTE prior assignment occurs here
foo(x); foo(x);
unsafe { unsafe {
asm!("mov $1, $0" : "=r"(x) : "r"(5_usize)); asm!("mov $1, $0" : "=r"(x) : "r"(5));
//~^ ERROR re-assignment of immutable variable `x` //~^ ERROR re-assignment of immutable variable `x`
} }
foo(x); foo(x);

View file

@ -19,7 +19,7 @@ fn foo(x: isize) { println!("{}", x); }
pub fn main() { pub fn main() {
let x: isize; let x: isize;
unsafe { unsafe {
asm!("mov $1, $0" : "r"(x) : "r"(5_usize)); //~ ERROR output operand constraint lacks '=' asm!("mov $1, $0" : "r"(x) : "r"(5)); //~ ERROR output operand constraint lacks '='
} }
foo(x); foo(x);
} }

View file

@ -15,7 +15,7 @@ struct cat {
} }
impl cat { impl cat {
pub fn speak(&self) { self.meows += 1_usize; } pub fn speak(&self) { self.meows += 1; }
} }
fn cat(in_x : usize, in_y : isize) -> cat { fn cat(in_x : usize, in_y : isize) -> cat {
@ -26,6 +26,6 @@ fn cat(in_x : usize, in_y : isize) -> cat {
} }
fn main() { fn main() {
let nyan : cat = cat(52_usize, 99); let nyan : cat = cat(52, 99);
nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method
} }

View file

@ -11,7 +11,7 @@
// Tests that a function with a ! annotation always actually fails // Tests that a function with a ! annotation always actually fails
fn bad_bang(i: usize) -> ! { fn bad_bang(i: usize) -> ! {
return 7_usize; //~ ERROR `return` in a function declared as diverging [E0166] return 7; //~ ERROR `return` in a function declared as diverging [E0166]
} }
fn main() { bad_bang(5); } fn main() { bad_bang(5); }

View file

@ -11,7 +11,7 @@
// Tests that a function with a ! annotation always actually fails // Tests that a function with a ! annotation always actually fails
fn bad_bang(i: usize) -> ! { //~ ERROR computation may converge in a function marked as diverging fn bad_bang(i: usize) -> ! { //~ ERROR computation may converge in a function marked as diverging
if i < 0_usize { } else { panic!(); } if i < 0 { } else { panic!(); }
} }
fn main() { bad_bang(5); } fn main() { bad_bang(5); }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
static i: String = 10i32; static i: String = 10;
//~^ ERROR mismatched types //~^ ERROR mismatched types
//~| expected `collections::string::String` //~| expected `collections::string::String`
//~| found `i32` //~| found `i32`

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
fn foo<T:'static>() { fn foo<T:'static>() {
1_usize.bar::<T>(); //~ ERROR `core::marker::Send` is not implemented 1.bar::<T>(); //~ ERROR `core::marker::Send` is not implemented
} }
trait bar { trait bar {

View file

@ -10,4 +10,4 @@
// error-pattern:`&&` cannot be applied to type `i32` // error-pattern:`&&` cannot be applied to type `i32`
fn main() { let x = 1i32 && 2i32; } fn main() { let x = 1 && 2; }

Some files were not shown because too many files have changed in this diff Show more