Skip to content

Commit ee76be5

Browse files
committed
Remove unnecessary as usize
1 parent 5825c72 commit ee76be5

File tree

10 files changed

+76
-76
lines changed

10 files changed

+76
-76
lines changed

src/libcollections/bit.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ fn blocks_for_bits(bits: usize) -> usize {
191191
//
192192
// Note that we can technically avoid this branch with the expression
193193
// `(nbits + u32::BITS - 1) / 32::BITS`, but if nbits is almost usize::MAX this will overflow.
194-
if bits % u32::BITS as usize == 0 {
195-
bits / u32::BITS as usize
194+
if bits % u32::BITS == 0 {
195+
bits / u32::BITS
196196
} else {
197-
bits / u32::BITS as usize + 1
197+
bits / u32::BITS + 1
198198
}
199199
}
200200

201201
/// Computes the bitmask for the final word of the vector
202202
fn mask_for_bits(bits: usize) -> u32 {
203203
// Note especially that a perfect multiple of u32::BITS should mask all 1s.
204-
!0 >> (u32::BITS as usize - bits % u32::BITS as usize) % u32::BITS as usize
204+
!0 >> (u32::BITS - bits % u32::BITS) % u32::BITS
205205
}
206206

207207
impl BitVec {
@@ -239,7 +239,7 @@ impl BitVec {
239239
/// An operation might screw up the unused bits in the last block of the
240240
/// `BitVec`. As per (3), it's assumed to be all 0s. This method fixes it up.
241241
fn fix_last_block(&mut self) {
242-
let extra_bits = self.len() % u32::BITS as usize;
242+
let extra_bits = self.len() % u32::BITS;
243243
if extra_bits > 0 {
244244
let mask = (1 << extra_bits) - 1;
245245
let storage_len = self.storage.len();
@@ -318,7 +318,7 @@ impl BitVec {
318318
/// false, false, true, false]));
319319
/// ```
320320
pub fn from_bytes(bytes: &[u8]) -> BitVec {
321-
let len = bytes.len().checked_mul(u8::BITS as usize).expect("capacity overflow");
321+
let len = bytes.len().checked_mul(u8::BITS).expect("capacity overflow");
322322
let mut bit_vec = BitVec::with_capacity(len);
323323
let complete_words = bytes.len() / 4;
324324
let extra_bytes = bytes.len() % 4;
@@ -387,8 +387,8 @@ impl BitVec {
387387
if i >= self.nbits {
388388
return None;
389389
}
390-
let w = i / u32::BITS as usize;
391-
let b = i % u32::BITS as usize;
390+
let w = i / u32::BITS;
391+
let b = i % u32::BITS;
392392
self.storage.get(w).map(|&block|
393393
(block & (1 << b)) != 0
394394
)
@@ -415,8 +415,8 @@ impl BitVec {
415415
reason = "panic semantics are likely to change in the future")]
416416
pub fn set(&mut self, i: usize, x: bool) {
417417
assert!(i < self.nbits);
418-
let w = i / u32::BITS as usize;
419-
let b = i % u32::BITS as usize;
418+
let w = i / u32::BITS;
419+
let b = i % u32::BITS;
420420
let flag = 1 << b;
421421
let val = if x { self.storage[w] | flag }
422422
else { self.storage[w] & !flag };
@@ -812,7 +812,7 @@ impl BitVec {
812812
#[inline]
813813
#[stable(feature = "rust1", since = "1.0.0")]
814814
pub fn capacity(&self) -> usize {
815-
self.storage.capacity().checked_mul(u32::BITS as usize).unwrap_or(usize::MAX)
815+
self.storage.capacity().checked_mul(u32::BITS).unwrap_or(usize::MAX)
816816
}
817817

818818
/// Grows the `BitVec` in-place, adding `n` copies of `value` to the `BitVec`.
@@ -843,7 +843,7 @@ impl BitVec {
843843

844844
// Correct the old tail word, setting or clearing formerly unused bits
845845
let num_cur_blocks = blocks_for_bits(self.nbits);
846-
if self.nbits % u32::BITS as usize > 0 {
846+
if self.nbits % u32::BITS > 0 {
847847
let mask = mask_for_bits(self.nbits);
848848
if value {
849849
self.storage[num_cur_blocks - 1] |= !mask;
@@ -893,7 +893,7 @@ impl BitVec {
893893
// (3)
894894
self.set(i, false);
895895
self.nbits = i;
896-
if self.nbits % u32::BITS as usize == 0 {
896+
if self.nbits % u32::BITS == 0 {
897897
// (2)
898898
self.storage.pop();
899899
}
@@ -916,7 +916,7 @@ impl BitVec {
916916
/// ```
917917
#[stable(feature = "rust1", since = "1.0.0")]
918918
pub fn push(&mut self, elem: bool) {
919-
if self.nbits % u32::BITS as usize == 0 {
919+
if self.nbits % u32::BITS == 0 {
920920
self.storage.push(0);
921921
}
922922
let insert_pos = self.nbits;
@@ -1442,7 +1442,7 @@ impl BitSet {
14421442
// Truncate
14431443
let trunc_len = cmp::max(old_len - n, 1);
14441444
bit_vec.storage.truncate(trunc_len);
1445-
bit_vec.nbits = trunc_len * u32::BITS as usize;
1445+
bit_vec.nbits = trunc_len * u32::BITS;
14461446
}
14471447

14481448
/// Iterator over each u32 stored in the `BitSet`.
@@ -1880,13 +1880,13 @@ impl<'a> Iterator for TwoBitPositions<'a> {
18801880
fn next(&mut self) -> Option<usize> {
18811881
while self.next_idx < self.set.bit_vec.len() ||
18821882
self.next_idx < self.other.bit_vec.len() {
1883-
let bit_idx = self.next_idx % u32::BITS as usize;
1883+
let bit_idx = self.next_idx % u32::BITS;
18841884
if bit_idx == 0 {
18851885
let s_bit_vec = &self.set.bit_vec;
18861886
let o_bit_vec = &self.other.bit_vec;
18871887
// Merging the two words is a bit of an awkward dance since
18881888
// one BitVec might be longer than the other
1889-
let word_idx = self.next_idx / u32::BITS as usize;
1889+
let word_idx = self.next_idx / u32::BITS;
18901890
let w1 = if word_idx < s_bit_vec.storage.len() {
18911891
s_bit_vec.storage[word_idx]
18921892
} else { 0 };

src/libcollections/enum_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub trait CLike {
8383
fn bit<E:CLike>(e: &E) -> usize {
8484
use core::usize;
8585
let value = e.to_usize();
86-
assert!(value < usize::BITS as usize,
86+
assert!(value < usize::BITS,
8787
"EnumSet only supports up to {} variants.", usize::BITS - 1);
8888
1 << value
8989
}

src/libcollectionstest/bit/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ mod bench {
408408
let mut bit_vec = BitSet::new();
409409
b.iter(|| {
410410
for _ in 0..100 {
411-
bit_vec.insert((r.next_u32() as usize) % u32::BITS as usize);
411+
bit_vec.insert((r.next_u32() as usize) % u32::BITS);
412412
}
413413
black_box(&bit_vec);
414414
});

src/libcollectionstest/bit/vec.rs

+40-40
Original file line numberDiff line numberDiff line change
@@ -541,70 +541,70 @@ fn test_big_bit_vec_tests() {
541541

542542
#[test]
543543
fn test_bit_vec_push_pop() {
544-
let mut s = BitVec::from_elem(5 * u32::BITS as usize - 2, false);
545-
assert_eq!(s.len(), 5 * u32::BITS as usize - 2);
546-
assert_eq!(s[5 * u32::BITS as usize - 3], false);
544+
let mut s = BitVec::from_elem(5 * u32::BITS - 2, false);
545+
assert_eq!(s.len(), 5 * u32::BITS - 2);
546+
assert_eq!(s[5 * u32::BITS - 3], false);
547547
s.push(true);
548548
s.push(true);
549-
assert_eq!(s[5 * u32::BITS as usize - 2], true);
550-
assert_eq!(s[5 * u32::BITS as usize - 1], true);
549+
assert_eq!(s[5 * u32::BITS - 2], true);
550+
assert_eq!(s[5 * u32::BITS - 1], true);
551551
// Here the internal vector will need to be extended
552552
s.push(false);
553-
assert_eq!(s[5 * u32::BITS as usize], false);
553+
assert_eq!(s[5 * u32::BITS], false);
554554
s.push(false);
555-
assert_eq!(s[5 * u32::BITS as usize + 1], false);
556-
assert_eq!(s.len(), 5 * u32::BITS as usize + 2);
555+
assert_eq!(s[5 * u32::BITS + 1], false);
556+
assert_eq!(s.len(), 5 * u32::BITS + 2);
557557
// Pop it all off
558558
assert_eq!(s.pop(), Some(false));
559559
assert_eq!(s.pop(), Some(false));
560560
assert_eq!(s.pop(), Some(true));
561561
assert_eq!(s.pop(), Some(true));
562-
assert_eq!(s.len(), 5 * u32::BITS as usize - 2);
562+
assert_eq!(s.len(), 5 * u32::BITS - 2);
563563
}
564564

565565
#[test]
566566
fn test_bit_vec_truncate() {
567-
let mut s = BitVec::from_elem(5 * u32::BITS as usize, true);
567+
let mut s = BitVec::from_elem(5 * u32::BITS, true);
568568

569-
assert_eq!(s, BitVec::from_elem(5 * u32::BITS as usize, true));
570-
assert_eq!(s.len(), 5 * u32::BITS as usize);
571-
s.truncate(4 * u32::BITS as usize);
572-
assert_eq!(s, BitVec::from_elem(4 * u32::BITS as usize, true));
573-
assert_eq!(s.len(), 4 * u32::BITS as usize);
569+
assert_eq!(s, BitVec::from_elem(5 * u32::BITS, true));
570+
assert_eq!(s.len(), 5 * u32::BITS);
571+
s.truncate(4 * u32::BITS);
572+
assert_eq!(s, BitVec::from_elem(4 * u32::BITS, true));
573+
assert_eq!(s.len(), 4 * u32::BITS);
574574
// Truncating to a size > s.len() should be a noop
575-
s.truncate(5 * u32::BITS as usize);
576-
assert_eq!(s, BitVec::from_elem(4 * u32::BITS as usize, true));
577-
assert_eq!(s.len(), 4 * u32::BITS as usize);
578-
s.truncate(3 * u32::BITS as usize - 10);
579-
assert_eq!(s, BitVec::from_elem(3 * u32::BITS as usize - 10, true));
580-
assert_eq!(s.len(), 3 * u32::BITS as usize - 10);
575+
s.truncate(5 * u32::BITS);
576+
assert_eq!(s, BitVec::from_elem(4 * u32::BITS, true));
577+
assert_eq!(s.len(), 4 * u32::BITS);
578+
s.truncate(3 * u32::BITS - 10);
579+
assert_eq!(s, BitVec::from_elem(3 * u32::BITS - 10, true));
580+
assert_eq!(s.len(), 3 * u32::BITS - 10);
581581
s.truncate(0);
582582
assert_eq!(s, BitVec::from_elem(0, true));
583583
assert_eq!(s.len(), 0);
584584
}
585585

586586
#[test]
587587
fn test_bit_vec_reserve() {
588-
let mut s = BitVec::from_elem(5 * u32::BITS as usize, true);
588+
let mut s = BitVec::from_elem(5 * u32::BITS, true);
589589
// Check capacity
590-
assert!(s.capacity() >= 5 * u32::BITS as usize);
591-
s.reserve(2 * u32::BITS as usize);
592-
assert!(s.capacity() >= 7 * u32::BITS as usize);
593-
s.reserve(7 * u32::BITS as usize);
594-
assert!(s.capacity() >= 12 * u32::BITS as usize);
595-
s.reserve_exact(7 * u32::BITS as usize);
596-
assert!(s.capacity() >= 12 * u32::BITS as usize);
597-
s.reserve(7 * u32::BITS as usize + 1);
598-
assert!(s.capacity() >= 12 * u32::BITS as usize + 1);
590+
assert!(s.capacity() >= 5 * u32::BITS);
591+
s.reserve(2 * u32::BITS);
592+
assert!(s.capacity() >= 7 * u32::BITS);
593+
s.reserve(7 * u32::BITS);
594+
assert!(s.capacity() >= 12 * u32::BITS);
595+
s.reserve_exact(7 * u32::BITS);
596+
assert!(s.capacity() >= 12 * u32::BITS);
597+
s.reserve(7 * u32::BITS + 1);
598+
assert!(s.capacity() >= 12 * u32::BITS + 1);
599599
// Check that length hasn't changed
600-
assert_eq!(s.len(), 5 * u32::BITS as usize);
600+
assert_eq!(s.len(), 5 * u32::BITS);
601601
s.push(true);
602602
s.push(false);
603603
s.push(true);
604-
assert_eq!(s[5 * u32::BITS as usize - 1], true);
605-
assert_eq!(s[5 * u32::BITS as usize - 0], true);
606-
assert_eq!(s[5 * u32::BITS as usize + 1], false);
607-
assert_eq!(s[5 * u32::BITS as usize + 2], true);
604+
assert_eq!(s[5 * u32::BITS - 1], true);
605+
assert_eq!(s[5 * u32::BITS - 0], true);
606+
assert_eq!(s[5 * u32::BITS + 1], false);
607+
assert_eq!(s[5 * u32::BITS + 2], true);
608608
}
609609

610610
#[test]
@@ -650,7 +650,7 @@ mod bench {
650650
let mut bit_vec = 0 as usize;
651651
b.iter(|| {
652652
for _ in 0..100 {
653-
bit_vec |= 1 << ((r.next_u32() as usize) % u32::BITS as usize);
653+
bit_vec |= 1 << ((r.next_u32() as usize) % u32::BITS);
654654
}
655655
black_box(&bit_vec);
656656
});
@@ -683,10 +683,10 @@ mod bench {
683683
#[bench]
684684
fn bench_bit_set_small(b: &mut Bencher) {
685685
let mut r = rng();
686-
let mut bit_vec = BitVec::from_elem(u32::BITS as usize, false);
686+
let mut bit_vec = BitVec::from_elem(u32::BITS, false);
687687
b.iter(|| {
688688
for _ in 0..100 {
689-
bit_vec.set((r.next_u32() as usize) % u32::BITS as usize, true);
689+
bit_vec.set((r.next_u32() as usize) % u32::BITS, true);
690690
}
691691
black_box(&bit_vec);
692692
});
@@ -703,7 +703,7 @@ mod bench {
703703

704704
#[bench]
705705
fn bench_bit_vec_small_iter(b: &mut Bencher) {
706-
let bit_vec = BitVec::from_elem(u32::BITS as usize, false);
706+
let bit_vec = BitVec::from_elem(u32::BITS, false);
707707
b.iter(|| {
708708
let mut sum = 0;
709709
for _ in 0..10 {

src/libcore/hash/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod impls {
194194
fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
195195
// FIXME(#23542) Replace with type ascription.
196196
#![allow(trivial_casts)]
197-
let newlen = data.len() * ::$ty::BYTES as usize;
197+
let newlen = data.len() * ::$ty::BYTES;
198198
let ptr = data.as_ptr() as *const u8;
199199
state.write(unsafe { slice::from_raw_parts(ptr, newlen) })
200200
}

src/librustc/middle/dataflow.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
195195
oper: O,
196196
id_range: IdRange,
197197
bits_per_id: usize) -> DataFlowContext<'a, 'tcx, O> {
198-
let words_per_id = (bits_per_id + usize::BITS as usize - 1) / usize::BITS as usize;
198+
let words_per_id = (bits_per_id + usize::BITS - 1) / usize::BITS;
199199
let num_nodes = cfg.graph.all_nodes().len();
200200

201201
debug!("DataFlowContext::new(analysis_name: {}, id_range={:?}, \
@@ -367,7 +367,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
367367
368368
for (word_index, &word) in words.iter().enumerate() {
369369
if word != 0 {
370-
let base_index = word_index * usize::BITS as usize;
370+
let base_index = word_index * usize::BITS;
371371
for offset in 0..usize::BITS {
372372
let bit = 1 << offset;
373373
if (word & bit) != 0 {
@@ -601,8 +601,8 @@ fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize],
601601
fn set_bit(words: &mut [usize], bit: usize) -> bool {
602602
debug!("set_bit: words={} bit={}",
603603
mut_bits_to_string(words), bit_str(bit));
604-
let word = bit / usize::BITS as usize;
605-
let bit_in_word = bit % usize::BITS as usize;
604+
let word = bit / usize::BITS;
605+
let bit_in_word = bit % usize::BITS;
606606
let bit_mask = 1 << bit_in_word;
607607
debug!("word={} bit_in_word={} bit_mask={}", word, bit_in_word, word);
608608
let oldv = words[word];

src/libstd/old_io/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -726,28 +726,28 @@ pub trait Reader {
726726
///
727727
/// The number of bytes returned is system-dependent.
728728
fn read_le_uint(&mut self) -> IoResult<usize> {
729-
self.read_le_uint_n(usize::BYTES as usize).map(|i| i as usize)
729+
self.read_le_uint_n(usize::BYTES).map(|i| i as usize)
730730
}
731731

732732
/// Reads a little-endian integer.
733733
///
734734
/// The number of bytes returned is system-dependent.
735735
fn read_le_int(&mut self) -> IoResult<isize> {
736-
self.read_le_int_n(isize::BYTES as usize).map(|i| i as isize)
736+
self.read_le_int_n(isize::BYTES).map(|i| i as isize)
737737
}
738738

739739
/// Reads a big-endian unsigned integer.
740740
///
741741
/// The number of bytes returned is system-dependent.
742742
fn read_be_uint(&mut self) -> IoResult<usize> {
743-
self.read_be_uint_n(usize::BYTES as usize).map(|i| i as usize)
743+
self.read_be_uint_n(usize::BYTES).map(|i| i as usize)
744744
}
745745

746746
/// Reads a big-endian integer.
747747
///
748748
/// The number of bytes returned is system-dependent.
749749
fn read_be_int(&mut self) -> IoResult<isize> {
750-
self.read_be_int_n(isize::BYTES as usize).map(|i| i as isize)
750+
self.read_be_int_n(isize::BYTES).map(|i| i as isize)
751751
}
752752

753753
/// Reads a big-endian `u64`.
@@ -1110,25 +1110,25 @@ pub trait Writer {
11101110
/// Write a little-endian usize (number of bytes depends on system).
11111111
#[inline]
11121112
fn write_le_uint(&mut self, n: usize) -> IoResult<()> {
1113-
extensions::u64_to_le_bytes(n as u64, usize::BYTES as usize, |v| self.write_all(v))
1113+
extensions::u64_to_le_bytes(n as u64, usize::BYTES, |v| self.write_all(v))
11141114
}
11151115

11161116
/// Write a little-endian isize (number of bytes depends on system).
11171117
#[inline]
11181118
fn write_le_int(&mut self, n: isize) -> IoResult<()> {
1119-
extensions::u64_to_le_bytes(n as u64, isize::BYTES as usize, |v| self.write_all(v))
1119+
extensions::u64_to_le_bytes(n as u64, isize::BYTES, |v| self.write_all(v))
11201120
}
11211121

11221122
/// Write a big-endian usize (number of bytes depends on system).
11231123
#[inline]
11241124
fn write_be_uint(&mut self, n: usize) -> IoResult<()> {
1125-
extensions::u64_to_be_bytes(n as u64, usize::BYTES as usize, |v| self.write_all(v))
1125+
extensions::u64_to_be_bytes(n as u64, usize::BYTES, |v| self.write_all(v))
11261126
}
11271127

11281128
/// Write a big-endian isize (number of bytes depends on system).
11291129
#[inline]
11301130
fn write_be_int(&mut self, n: isize) -> IoResult<()> {
1131-
extensions::u64_to_be_bytes(n as u64, isize::BYTES as usize, |v| self.write_all(v))
1131+
extensions::u64_to_be_bytes(n as u64, isize::BYTES, |v| self.write_all(v))
11321132
}
11331133

11341134
/// Write a big-endian u64 (8 bytes).

src/libstd/sys/unix/c.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ mod select {
194194
#[repr(C)]
195195
pub struct fd_set {
196196
// FIXME: shouldn't this be a c_ulong?
197-
fds_bits: [libc::uintptr_t; (FD_SETSIZE / usize::BITS as usize)]
197+
fds_bits: [libc::uintptr_t; (FD_SETSIZE / usize::BITS)]
198198
}
199199

200200
pub fn fd_set(set: &mut fd_set, fd: i32) {
201201
let fd = fd as usize;
202-
set.fds_bits[fd / usize::BITS as usize] |= 1 << (fd % usize::BITS as usize);
202+
set.fds_bits[fd / usize::BITS] |= 1 << (fd % usize::BITS);
203203
}
204204
}
205205

0 commit comments

Comments
 (0)