about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-12 11:05:30 +0000
committerbors <bors@rust-lang.org>2015-01-12 11:05:30 +0000
commita6408fa1d80191032bebfa0047bc597b746886a5 (patch)
tree8cd568a490644ead95d16160dad26547085f4684
parentb21a6da340fd958de370d2b83c0f17fd8fa51f89 (diff)
parent348d833187a2cf90b0d39f5fe1f0ce9564036e68 (diff)
downloadrust-a6408fa1d80191032bebfa0047bc597b746886a5.tar.gz
rust-a6408fa1d80191032bebfa0047bc597b746886a5.zip
auto merge of #20942 : nagisa/rust/shrl-impls, r=nikomatsakis
This is only relevant to the code that uses generics such as

    fn magic<T: Shl>(a: T) { a << 10u8; }

r? @nikomatsakis 
-rw-r--r--src/libcore/ops.rs68
1 files changed, 60 insertions, 8 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index ab956587d82..e7eb307689f 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -706,20 +706,45 @@ pub trait Shl<RHS> {
 }
 
 macro_rules! shl_impl {
-    ($($t:ty)*) => ($(
+    ($t:ty, $f:ty) => (
         #[stable]
-        impl Shl<uint> for $t {
+        impl Shl<$f> for $t {
             type Output = $t;
 
             #[inline]
-            fn shl(self, other: uint) -> $t {
+            fn shl(self, other: $f) -> $t {
                 self << other
             }
         }
+    )
+}
+
+// SNAP 9e4e524e0
+#[cfg(not(stage0))]
+macro_rules! shl_impl_all {
+    ($($t:ty)*) => ($(
+        shl_impl! { $t, u8 }
+        shl_impl! { $t, u16 }
+        shl_impl! { $t, u32 }
+        shl_impl! { $t, u64 }
+        shl_impl! { $t, usize }
+
+        shl_impl! { $t, i8 }
+        shl_impl! { $t, i16 }
+        shl_impl! { $t, i32 }
+        shl_impl! { $t, i64 }
+        shl_impl! { $t, isize }
     )*)
 }
 
-shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
+#[cfg(stage0)]
+macro_rules! shl_impl_all {
+    ($($t:ty)*) => ($(
+        shl_impl! { $t, usize }
+    )*)
+}
+
+shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
 
 /// The `Shr` trait is used to specify the functionality of `>>`.
 ///
@@ -761,17 +786,44 @@ pub trait Shr<RHS> {
 }
 
 macro_rules! shr_impl {
-    ($($t:ty)*) => ($(
-        impl Shr<uint> for $t {
+    ($t:ty, $f:ty) => (
+        impl Shr<$f> for $t {
             type Output = $t;
 
             #[inline]
-            fn shr(self, other: uint) -> $t { self >> other }
+            fn shr(self, other: $f) -> $t {
+                self >> other
+            }
         }
+    )
+}
+
+// SNAP 9e4e524e0
+#[cfg(not(stage0))]
+macro_rules! shr_impl_all {
+    ($($t:ty)*) => ($(
+        shr_impl! { $t, u8 }
+        shr_impl! { $t, u16 }
+        shr_impl! { $t, u32 }
+        shr_impl! { $t, u64 }
+        shr_impl! { $t, usize }
+
+        shr_impl! { $t, i8 }
+        shr_impl! { $t, i16 }
+        shr_impl! { $t, i32 }
+        shr_impl! { $t, i64 }
+        shr_impl! { $t, isize }
+    )*)
+}
+
+#[cfg(stage0)]
+macro_rules! shr_impl_all {
+    ($($t:ty)*) => ($(
+        shr_impl! { $t, usize }
     )*)
 }
 
-shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
+shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
 
 /// The `Index` trait is used to specify the functionality of indexing operations
 /// like `arr[idx]` when used in an immutable context.