Skip to content

Commit 7b7d23c

Browse files
committed
Change Shl<T, T> for Int to Shl<uint, T>
1 parent d623a8b commit 7b7d23c

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

Diff for: src/libcore/num/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ pub trait Int: Primitive
400400
+ BitAnd<Self,Self>
401401
+ BitOr<Self,Self>
402402
+ BitXor<Self,Self>
403-
+ Shl<Self,Self>
404-
+ Shr<Self,Self> {
403+
+ Shl<uint,Self>
404+
+ Shr<uint,Self> {
405405
/// Returns the number of ones in the binary representation of the integer.
406406
///
407407
/// # Example
@@ -667,12 +667,12 @@ int_cast_impl!(i64, u64)
667667
/// Returns the smallest power of 2 greater than or equal to `n`.
668668
#[inline]
669669
pub fn next_power_of_two<T: Unsigned + Int>(n: T) -> T {
670-
let halfbits: T = cast(size_of::<T>() * 4).unwrap();
670+
let halfbits = size_of::<T>() * 4;
671671
let mut tmp: T = n - one();
672-
let mut shift: T = one();
672+
let mut shift = 1u;
673673
while shift <= halfbits {
674674
tmp = tmp | (tmp >> shift);
675-
shift = shift << one();
675+
shift = shift << 1u;
676676
}
677677
tmp + one()
678678
}
@@ -688,12 +688,12 @@ pub fn is_power_of_two<T: Unsigned + Int>(n: T) -> bool {
688688
/// otherwise the power of 2 is wrapped in `Some`.
689689
#[inline]
690690
pub fn checked_next_power_of_two<T: Unsigned + Int>(n: T) -> Option<T> {
691-
let halfbits: T = cast(size_of::<T>() * 4).unwrap();
691+
let halfbits = size_of::<T>() * 4;
692692
let mut tmp: T = n - one();
693-
let mut shift: T = one();
693+
let mut shift = 1u;
694694
while shift <= halfbits {
695695
tmp = tmp | (tmp >> shift);
696-
shift = shift << one();
696+
shift = shift << 1u;
697697
}
698698
tmp.checked_add(&one())
699699
}

Diff for: src/libcore/ops.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ pub trait Shl<RHS,Result> {
558558

559559
macro_rules! shl_impl(
560560
($($t:ty)*) => ($(
561-
impl Shl<$t, $t> for $t {
561+
impl Shl<uint, $t> for $t {
562562
#[inline]
563-
fn shl(&self, other: &$t) -> $t {
564-
(*self) << (*other as uint)
563+
fn shl(&self, other: &uint) -> $t {
564+
(*self) << (*other)
565565
}
566566
}
567567
)*)
@@ -601,9 +601,9 @@ pub trait Shr<RHS,Result> {
601601

602602
macro_rules! shr_impl(
603603
($($t:ty)*) => ($(
604-
impl Shr<$t, $t> for $t {
604+
impl Shr<uint, $t> for $t {
605605
#[inline]
606-
fn shr(&self, other: &$t) -> $t { (*self) >> (*other as uint) }
606+
fn shr(&self, other: &uint) -> $t { (*self) >> (*other) }
607607
}
608608
)*)
609609
)

Diff for: src/libcoretest/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ mod tests {
7474
assert!(0b1110 as $T == (0b1100 as $T).bitor(&(0b1010 as $T)));
7575
assert!(0b1000 as $T == (0b1100 as $T).bitand(&(0b1010 as $T)));
7676
assert!(0b0110 as $T == (0b1100 as $T).bitxor(&(0b1010 as $T)));
77-
assert!(0b1110 as $T == (0b0111 as $T).shl(&(1 as $T)));
78-
assert!(0b0111 as $T == (0b1110 as $T).shr(&(1 as $T)));
77+
assert!(0b1110 as $T == (0b0111 as $T).shl(&1));
78+
assert!(0b0111 as $T == (0b1110 as $T).shr(&1));
7979
assert!(-(0b11 as $T) - (1 as $T) == (0b11 as $T).not());
8080
}
8181

Diff for: src/libcoretest/num/uint_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ mod tests {
3434
assert!(0b1110 as $T == (0b1100 as $T).bitor(&(0b1010 as $T)));
3535
assert!(0b1000 as $T == (0b1100 as $T).bitand(&(0b1010 as $T)));
3636
assert!(0b0110 as $T == (0b1100 as $T).bitxor(&(0b1010 as $T)));
37-
assert!(0b1110 as $T == (0b0111 as $T).shl(&(1 as $T)));
38-
assert!(0b0111 as $T == (0b1110 as $T).shr(&(1 as $T)));
37+
assert!(0b1110 as $T == (0b0111 as $T).shl(&1u));
38+
assert!(0b0111 as $T == (0b1110 as $T).shr(&1u));
3939
assert!(MAX - (0b1011 as $T) == (0b1011 as $T).not());
4040
}
4141

0 commit comments

Comments
 (0)