Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 1 | pub use self::imp::*; |
| 2 | |
| 3 | #[cfg(not(dox))] |
| 4 | mod imp { |
Alex Crichton | f7efe34 | 2015-11-02 14:26:04 -0800 | [diff] [blame] | 5 | pub use core::option::Option; |
| 6 | pub use core::clone::Clone; |
| 7 | pub use core::marker::Copy; |
| 8 | pub use core::mem; |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 9 | } |
| 10 | |
| 11 | #[cfg(dox)] |
| 12 | mod imp { |
| 13 | pub enum Option<T> { |
| 14 | Some(T), |
| 15 | None, |
| 16 | } |
Alex Crichton | 0262b07 | 2015-09-17 17:53:03 -0700 | [diff] [blame] | 17 | impl<T: Copy> Copy for Option<T> {} |
Alex Crichton | 97a2c17 | 2015-09-17 17:28:45 -0700 | [diff] [blame] | 18 | impl<T: Clone> Clone for Option<T> { |
| 19 | fn clone(&self) -> Option<T> { loop {} } |
| 20 | } |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 21 | |
| 22 | pub trait Clone { |
| 23 | fn clone(&self) -> Self; |
| 24 | } |
| 25 | |
| 26 | #[lang = "copy"] |
| 27 | pub trait Copy {} |
| 28 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 29 | #[lang = "sync"] |
| 30 | pub trait Sync {} |
| 31 | impl<T> Sync for T {} |
| 32 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 33 | #[lang = "sized"] |
| 34 | pub trait Sized {} |
| 35 | |
| 36 | macro_rules! each_int { |
| 37 | ($mac:ident) => ( |
| 38 | $mac!(u8); |
| 39 | $mac!(u16); |
| 40 | $mac!(u32); |
| 41 | $mac!(u64); |
| 42 | $mac!(usize); |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 43 | each_signed_int!($mac); |
| 44 | ) |
| 45 | } |
| 46 | |
| 47 | macro_rules! each_signed_int { |
| 48 | ($mac:ident) => ( |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 49 | $mac!(i8); |
| 50 | $mac!(i16); |
| 51 | $mac!(i32); |
| 52 | $mac!(i64); |
| 53 | $mac!(isize); |
| 54 | ) |
| 55 | } |
| 56 | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 57 | #[lang = "div"] |
| 58 | pub trait Div<RHS> { |
| 59 | type Output; |
| 60 | fn div(self, rhs: RHS) -> Self::Output; |
| 61 | } |
| 62 | |
| 63 | macro_rules! impl_div { |
| 64 | ($($i:ident)*) => ($( |
| 65 | impl Div<$i> for $i { |
| 66 | type Output = $i; |
| 67 | fn div(self, rhs: $i) -> $i { self / rhs } |
| 68 | } |
| 69 | )*) |
| 70 | } |
| 71 | each_int!(impl_div); |
| 72 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 73 | #[lang = "shl"] |
| 74 | pub trait Shl<RHS> { |
| 75 | type Output; |
| 76 | fn shl(self, rhs: RHS) -> Self::Output; |
| 77 | } |
| 78 | |
| 79 | macro_rules! impl_shl { |
| 80 | ($($i:ident)*) => ($( |
| 81 | impl Shl<$i> for $i { |
| 82 | type Output = $i; |
| 83 | fn shl(self, rhs: $i) -> $i { self << rhs } |
| 84 | } |
| 85 | )*) |
| 86 | } |
| 87 | each_int!(impl_shl); |
| 88 | |
| 89 | #[lang = "mul"] |
| 90 | pub trait Mul<RHS=Self> { |
| 91 | type Output; |
| 92 | fn mul(self, rhs: RHS) -> Self::Output; |
| 93 | } |
| 94 | |
| 95 | macro_rules! impl_mul { |
| 96 | ($($i:ident)*) => ($( |
| 97 | impl Mul for $i { |
| 98 | type Output = $i; |
| 99 | fn mul(self, rhs: $i) -> $i { self * rhs } |
| 100 | } |
| 101 | )*) |
| 102 | } |
| 103 | each_int!(impl_mul); |
| 104 | |
| 105 | #[lang = "sub"] |
| 106 | pub trait Sub<RHS=Self> { |
| 107 | type Output; |
| 108 | fn sub(self, rhs: RHS) -> Self::Output; |
| 109 | } |
| 110 | |
| 111 | macro_rules! impl_sub { |
| 112 | ($($i:ident)*) => ($( |
| 113 | impl Sub for $i { |
| 114 | type Output = $i; |
| 115 | fn sub(self, rhs: $i) -> $i { self - rhs } |
| 116 | } |
| 117 | )*) |
| 118 | } |
| 119 | each_int!(impl_sub); |
| 120 | |
| 121 | #[lang = "bitor"] |
| 122 | pub trait Bitor<RHS=Self> { |
| 123 | type Output; |
| 124 | fn bitor(self, rhs: RHS) -> Self::Output; |
| 125 | } |
| 126 | |
| 127 | macro_rules! impl_bitor { |
| 128 | ($($i:ident)*) => ($( |
| 129 | impl Bitor for $i { |
| 130 | type Output = $i; |
| 131 | fn bitor(self, rhs: $i) -> $i { self | rhs } |
| 132 | } |
| 133 | )*) |
| 134 | } |
| 135 | each_int!(impl_bitor); |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 136 | |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 137 | #[lang = "neg"] |
| 138 | pub trait Neg { |
| 139 | type Output; |
| 140 | fn neg(self) -> Self::Output; |
| 141 | } |
| 142 | |
| 143 | macro_rules! impl_neg { |
| 144 | ($($i:ident)*) => ($( |
| 145 | impl Neg for $i { |
| 146 | type Output = $i; |
| 147 | fn neg(self) -> $i { -self } |
| 148 | } |
| 149 | )*) |
| 150 | } |
| 151 | each_signed_int!(impl_neg); |
| 152 | |
| 153 | #[lang = "not"] |
| 154 | pub trait Not { |
| 155 | type Output; |
| 156 | fn not(self) -> Self::Output; |
| 157 | } |
| 158 | |
| 159 | macro_rules! impl_not { |
| 160 | ($($i:ident)*) => ($( |
| 161 | impl Not for $i { |
| 162 | type Output = $i; |
| 163 | fn not(self) -> $i { !self } |
| 164 | } |
| 165 | )*) |
| 166 | } |
| 167 | each_int!(impl_not); |
| 168 | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 169 | pub mod mem { |
| 170 | pub fn size_of_val<T>(_: &T) -> usize { 4 } |
| 171 | } |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 172 | } |