Skip to content

Commit a6408fa

Browse files
committed
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
2 parents b21a6da + 348d833 commit a6408fa

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

src/libcore/ops.rs

+60-8
Original file line numberDiff line numberDiff line change
@@ -706,20 +706,45 @@ pub trait Shl<RHS> {
706706
}
707707

708708
macro_rules! shl_impl {
709-
($($t:ty)*) => ($(
709+
($t:ty, $f:ty) => (
710710
#[stable]
711-
impl Shl<uint> for $t {
711+
impl Shl<$f> for $t {
712712
type Output = $t;
713713

714714
#[inline]
715-
fn shl(self, other: uint) -> $t {
715+
fn shl(self, other: $f) -> $t {
716716
self << other
717717
}
718718
}
719+
)
720+
}
721+
722+
// SNAP 9e4e524e0
723+
#[cfg(not(stage0))]
724+
macro_rules! shl_impl_all {
725+
($($t:ty)*) => ($(
726+
shl_impl! { $t, u8 }
727+
shl_impl! { $t, u16 }
728+
shl_impl! { $t, u32 }
729+
shl_impl! { $t, u64 }
730+
shl_impl! { $t, usize }
731+
732+
shl_impl! { $t, i8 }
733+
shl_impl! { $t, i16 }
734+
shl_impl! { $t, i32 }
735+
shl_impl! { $t, i64 }
736+
shl_impl! { $t, isize }
719737
)*)
720738
}
721739

722-
shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
740+
#[cfg(stage0)]
741+
macro_rules! shl_impl_all {
742+
($($t:ty)*) => ($(
743+
shl_impl! { $t, usize }
744+
)*)
745+
}
746+
747+
shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
723748

724749
/// The `Shr` trait is used to specify the functionality of `>>`.
725750
///
@@ -761,17 +786,44 @@ pub trait Shr<RHS> {
761786
}
762787

763788
macro_rules! shr_impl {
764-
($($t:ty)*) => ($(
765-
impl Shr<uint> for $t {
789+
($t:ty, $f:ty) => (
790+
impl Shr<$f> for $t {
766791
type Output = $t;
767792

768793
#[inline]
769-
fn shr(self, other: uint) -> $t { self >> other }
794+
fn shr(self, other: $f) -> $t {
795+
self >> other
796+
}
770797
}
798+
)
799+
}
800+
801+
// SNAP 9e4e524e0
802+
#[cfg(not(stage0))]
803+
macro_rules! shr_impl_all {
804+
($($t:ty)*) => ($(
805+
shr_impl! { $t, u8 }
806+
shr_impl! { $t, u16 }
807+
shr_impl! { $t, u32 }
808+
shr_impl! { $t, u64 }
809+
shr_impl! { $t, usize }
810+
811+
shr_impl! { $t, i8 }
812+
shr_impl! { $t, i16 }
813+
shr_impl! { $t, i32 }
814+
shr_impl! { $t, i64 }
815+
shr_impl! { $t, isize }
816+
)*)
817+
}
818+
819+
#[cfg(stage0)]
820+
macro_rules! shr_impl_all {
821+
($($t:ty)*) => ($(
822+
shr_impl! { $t, usize }
771823
)*)
772824
}
773825

774-
shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
826+
shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
775827

776828
/// The `Index` trait is used to specify the functionality of indexing operations
777829
/// like `arr[idx]` when used in an immutable context.

0 commit comments

Comments
 (0)