Skip to content

Commit

Permalink
Rollup merge of rust-lang#22994 - eddyb:unsuffix-ints-good, r=alexcri…
Browse files Browse the repository at this point in the history
…chton

 Automatic has-same-types testing methodology can be found in rust-lang#22501.
Because most of them don't work with `--pretty=typed`, compile-fail tests were manually audited.

r? @aturon
  • Loading branch information
Manishearth committed Mar 5, 2015
2 parents c8c4d85 + 34410ec commit 145b83e
Show file tree
Hide file tree
Showing 330 changed files with 1,114 additions and 1,116 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/boxed_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ fn test_show() {
#[test]
fn deref() {
fn homura<T: Deref<Target=i32>>(_: T) { }
homura(Box::new(765i32));
homura(Box::new(765));
}

#[test]
fn raw_sized() {
unsafe {
let x = Box::new(17i32);
let x = Box::new(17);
let p = boxed::into_raw(x);
assert_eq!(17, *p);
*p = 19;
Expand Down
24 changes: 12 additions & 12 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
if a_len < b_len {
(a.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(b_len).skip(a_len)),
b.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(0).skip(0)))
(a.blocks().enumerate().chain(iter::repeat(0).enumerate().take(b_len).skip(a_len)),
b.blocks().enumerate().chain(iter::repeat(0).enumerate().take(0).skip(0)))
} else {
(a.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(0).skip(0)),
b.blocks().enumerate().chain(iter::repeat(0u32).enumerate().take(a_len).skip(b_len)))
(a.blocks().enumerate().chain(iter::repeat(0).enumerate().take(0).skip(0)),
b.blocks().enumerate().chain(iter::repeat(0).enumerate().take(a_len).skip(b_len)))
}
}

Expand Down Expand Up @@ -199,7 +199,7 @@ fn blocks_for_bits(bits: usize) -> usize {
/// Computes the bitmask for the final word of the vector
fn mask_for_bits(bits: usize) -> u32 {
// 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 {
Expand Down Expand Up @@ -275,7 +275,7 @@ impl BitVec {
pub fn from_elem(nbits: usize, bit: bool) -> BitVec {
let nblocks = blocks_for_bits(nbits);
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
};
bit_vec.fix_last_block();
Expand Down Expand Up @@ -330,7 +330,7 @@ impl BitVec {
}

if extra_bytes > 0 {
let mut last_word = 0u32;
let mut last_word = 0;
for (i, &byte) in bytes[complete_words*4..].iter().enumerate() {
last_word |= (reverse_bits(byte) as u32) << (i * 8);
}
Expand Down Expand Up @@ -431,7 +431,7 @@ impl BitVec {
/// ```
#[inline]
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();
}

Expand Down Expand Up @@ -566,12 +566,12 @@ impl BitVec {
/// assert_eq!(bv.all(), false);
/// ```
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...
self.blocks().all(|elem| {
let tmp = last_word;
last_word = elem;
tmp == !0u32
tmp == !0
// and then check the last one has enough ones
}) && (last_word == mask_for_bits(self.nbits))
}
Expand Down Expand Up @@ -912,7 +912,7 @@ impl BitVec {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
for w in &mut self.storage { *w = 0u32; }
for w in &mut self.storage { *w = 0; }
}
}

Expand Down Expand Up @@ -2313,7 +2313,7 @@ mod tests {

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();
assert_eq!(bit_vec.iter().collect::<Vec<bool>>(), long)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
//! 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!("{} {:?}", "foo\n", "bar\n"), "foo\n \"bar\\n\"");
//! ```
Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ mod tests {
#[test]
fn test_bytes_set_memory() {
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);
assert!(values == [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]);
values[2..4].set_memory(0xFF);
Expand Down Expand Up @@ -2809,26 +2809,26 @@ mod tests {
fn test_mut_chunks() {
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);
for (i, chunk) in v.chunks_mut(3).enumerate() {
for x in chunk {
*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);
}

#[test]
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 x in chunk {
*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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ macro_rules! utf8_first_byte {

// return the value of $ch updated with continuation byte $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")]
Expand Down Expand Up @@ -2300,8 +2300,8 @@ mod tests {

#[test]
fn test_chars_decoding() {
let mut bytes = [0u8; 4];
for c in (0u32..0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let mut bytes = [0; 4];
for c in (0..0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
if Some(c) != s.chars().next() {
Expand All @@ -2312,8 +2312,8 @@ mod tests {

#[test]
fn test_chars_rev_decoding() {
let mut bytes = [0u8; 4];
for c in (0u32..0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let mut bytes = [0; 4];
for c in (0..0x110000).filter_map(|c| ::core::char::from_u32(c)) {
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
let s = ::core::str::from_utf8(&bytes[..len]).unwrap();
if Some(c) != s.chars().rev().next() {
Expand Down
72 changes: 36 additions & 36 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
let total = v.len();
fn unsafe_get(xs: &[u8], i: usize) -> u8 {
Expand Down Expand Up @@ -195,14 +195,14 @@ impl String {
}
})}

if byte < 128u8 {
if byte < 128 {
// subseqidx handles this
} else {
let w = unicode_str::utf8_char_width(byte);

match w {
2 => {
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 {
if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!();
continue;
}
Expand All @@ -220,7 +220,7 @@ impl String {
}
}
i += 1;
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 {
if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!();
continue;
}
Expand All @@ -237,12 +237,12 @@ impl String {
}
}
i += 1;
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 {
if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!();
continue;
}
i += 1;
if safe_get(v, i, total) & 192u8 != TAG_CONT_U8 {
if safe_get(v, i, total) & 192 != TAG_CONT_U8 {
error!();
continue;
}
Expand Down Expand Up @@ -1084,40 +1084,40 @@ mod tests {
fn test_from_utf16() {
let pairs =
[(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
vec![0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16,
0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16,
0xd800_u16, 0xdf30_u16, 0x000a_u16]),
vec![0xd800, 0xdf45, 0xd800, 0xdf3f,
0xd800, 0xdf3b, 0xd800, 0xdf46,
0xd800, 0xdf39, 0xd800, 0xdf3b,
0xd800, 0xdf30, 0x000a]),

(String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
vec![0xd801_u16, 0xdc12_u16, 0xd801_u16,
0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16,
0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16,
0xdc4b_u16, 0x0020_u16, 0xd801_u16, 0xdc0f_u16,
0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16,
0x000a_u16]),
vec![0xd801, 0xdc12, 0xd801,
0xdc49, 0xd801, 0xdc2e, 0xd801,
0xdc40, 0xd801, 0xdc32, 0xd801,
0xdc4b, 0x0020, 0xd801, 0xdc0f,
0xd801, 0xdc32, 0xd801, 0xdc4d,
0x000a]),

(String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
vec![0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16,
0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16,
0x00b7_u16, 0xd800_u16, 0xdf0c_u16, 0xd800_u16,
0xdf04_u16, 0xd800_u16, 0xdf15_u16, 0xd800_u16,
0xdf04_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16,
0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]),
vec![0xd800, 0xdf00, 0xd800, 0xdf16,
0xd800, 0xdf0b, 0xd800, 0xdf04,
0xd800, 0xdf11, 0xd800, 0xdf09,
0x00b7, 0xd800, 0xdf0c, 0xd800,
0xdf04, 0xd800, 0xdf15, 0xd800,
0xdf04, 0xd800, 0xdf0b, 0xd800,
0xdf09, 0xd800, 0xdf11, 0x000a ]),

(String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
vec![0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16,
0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16,
0x0020_u16, 0xd801_u16, 0xdc95_u16, 0xd801_u16,
0xdc93_u16, 0x0020_u16, 0xd801_u16, 0xdc88_u16,
0xd801_u16, 0xdc9a_u16, 0xd801_u16, 0xdc8d_u16,
0x0020_u16, 0xd801_u16, 0xdc8f_u16, 0xd801_u16,
0xdc9c_u16, 0xd801_u16, 0xdc92_u16, 0xd801_u16,
0xdc96_u16, 0xd801_u16, 0xdc86_u16, 0x0020_u16,
0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16,
0x000a_u16 ]),
vec![0xd801, 0xdc8b, 0xd801, 0xdc98,
0xd801, 0xdc88, 0xd801, 0xdc91,
0xd801, 0xdc9b, 0xd801, 0xdc92,
0x0020, 0xd801, 0xdc95, 0xd801,
0xdc93, 0x0020, 0xd801, 0xdc88,
0xd801, 0xdc9a, 0xd801, 0xdc8d,
0x0020, 0xd801, 0xdc8f, 0xd801,
0xdc9c, 0xd801, 0xdc92, 0xd801,
0xdc96, 0xd801, 0xdc86, 0x0020,
0xd801, 0xdc95, 0xd801, 0xdc86,
0x000a ]),
// Issue #12318, even-numbered non-BMP planes
(String::from_str("\u{20000}"),
vec![0xD840, 0xDC00])];
Expand Down Expand Up @@ -1303,7 +1303,7 @@ mod tests {
assert_eq!(1.to_string(), "1");
assert_eq!((-1).to_string(), "-1");
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!(false.to_string(), "false");
assert_eq!(("hi".to_string()).to_string(), "hi");
Expand Down Expand Up @@ -1421,7 +1421,7 @@ mod tests {

#[bench]
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(|| {
let _ = String::from_utf8_lossy(&s);
});
Expand Down
Loading

0 comments on commit 145b83e

Please sign in to comment.