Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 1 | pub use self::imp::*; |
| 2 | |
Francis Gagné | 18341fd | 2018-03-18 14:09:07 -0400 | [diff] [blame] | 3 | #[cfg(not(cross_platform_docs))] |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 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 | |
Francis Gagné | 18341fd | 2018-03-18 14:09:07 -0400 | [diff] [blame] | 11 | #[cfg(cross_platform_docs)] |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 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 | |
Mike Hommey | e2bfbc5 | 2018-04-05 11:40:06 +0900 | [diff] [blame] | 22 | impl<T> Copy for *mut T {} |
| 23 | impl<T> Clone for *mut T { |
| 24 | fn clone(&self) -> *mut T { loop {} } |
| 25 | } |
| 26 | |
| 27 | impl<T> Copy for *const T {} |
| 28 | impl<T> Clone for *const T { |
| 29 | fn clone(&self) -> *const T { loop {} } |
| 30 | } |
| 31 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 32 | pub trait Clone { |
| 33 | fn clone(&self) -> Self; |
| 34 | } |
| 35 | |
| 36 | #[lang = "copy"] |
| 37 | pub trait Copy {} |
| 38 | |
Alex Crichton | c0cf280 | 2017-05-25 16:06:01 -0700 | [diff] [blame] | 39 | #[lang = "freeze"] |
| 40 | pub trait Freeze {} |
| 41 | |
Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 42 | #[lang = "sync"] |
| 43 | pub trait Sync {} |
| 44 | impl<T> Sync for T {} |
| 45 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 46 | #[lang = "sized"] |
| 47 | pub trait Sized {} |
| 48 | |
| 49 | macro_rules! each_int { |
| 50 | ($mac:ident) => ( |
| 51 | $mac!(u8); |
| 52 | $mac!(u16); |
| 53 | $mac!(u32); |
| 54 | $mac!(u64); |
| 55 | $mac!(usize); |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 56 | each_signed_int!($mac); |
| 57 | ) |
| 58 | } |
| 59 | |
| 60 | macro_rules! each_signed_int { |
| 61 | ($mac:ident) => ( |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 62 | $mac!(i8); |
| 63 | $mac!(i16); |
| 64 | $mac!(i32); |
| 65 | $mac!(i64); |
| 66 | $mac!(isize); |
| 67 | ) |
| 68 | } |
| 69 | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 70 | #[lang = "div"] |
| 71 | pub trait Div<RHS> { |
| 72 | type Output; |
| 73 | fn div(self, rhs: RHS) -> Self::Output; |
| 74 | } |
| 75 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 76 | #[lang = "shl"] |
| 77 | pub trait Shl<RHS> { |
| 78 | type Output; |
| 79 | fn shl(self, rhs: RHS) -> Self::Output; |
| 80 | } |
| 81 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 82 | #[lang = "mul"] |
| 83 | pub trait Mul<RHS=Self> { |
| 84 | type Output; |
| 85 | fn mul(self, rhs: RHS) -> Self::Output; |
| 86 | } |
| 87 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 88 | #[lang = "sub"] |
| 89 | pub trait Sub<RHS=Self> { |
| 90 | type Output; |
| 91 | fn sub(self, rhs: RHS) -> Self::Output; |
| 92 | } |
| 93 | |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 94 | #[lang = "bitor"] |
| 95 | pub trait Bitor<RHS=Self> { |
| 96 | type Output; |
| 97 | fn bitor(self, rhs: RHS) -> Self::Output; |
| 98 | } |
| 99 | |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 100 | #[lang = "neg"] |
| 101 | pub trait Neg { |
| 102 | type Output; |
| 103 | fn neg(self) -> Self::Output; |
| 104 | } |
| 105 | |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 106 | #[lang = "not"] |
| 107 | pub trait Not { |
| 108 | type Output; |
| 109 | fn not(self) -> Self::Output; |
| 110 | } |
| 111 | |
Alex Crichton | 9029cfb | 2017-10-18 12:28:48 -0700 | [diff] [blame] | 112 | #[lang = "add"] |
| 113 | pub trait Add<RHS = Self> { |
| 114 | type Output; |
| 115 | fn add(self, r: RHS) -> Self::Output; |
| 116 | } |
| 117 | |
| 118 | macro_rules! impl_traits { |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 119 | ($($i:ident)*) => ($( |
Alex Crichton | 9029cfb | 2017-10-18 12:28:48 -0700 | [diff] [blame] | 120 | impl Div<$i> for $i { |
| 121 | type Output = $i; |
| 122 | fn div(self, rhs: $i) -> $i { self / rhs } |
| 123 | } |
| 124 | impl Shl<$i> for $i { |
| 125 | type Output = $i; |
| 126 | fn shl(self, rhs: $i) -> $i { self << rhs } |
| 127 | } |
| 128 | impl Mul for $i { |
| 129 | type Output = $i; |
| 130 | fn mul(self, rhs: $i) -> $i { self * rhs } |
| 131 | } |
| 132 | |
| 133 | impl Sub for $i { |
| 134 | type Output = $i; |
| 135 | fn sub(self, rhs: $i) -> $i { self - rhs } |
| 136 | } |
| 137 | impl Bitor for $i { |
| 138 | type Output = $i; |
| 139 | fn bitor(self, rhs: $i) -> $i { self | rhs } |
| 140 | } |
| 141 | impl Neg for $i { |
| 142 | type Output = $i; |
| 143 | fn neg(self) -> $i { -self } |
| 144 | } |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 145 | impl Not for $i { |
| 146 | type Output = $i; |
| 147 | fn not(self) -> $i { !self } |
| 148 | } |
Alex Crichton | 9029cfb | 2017-10-18 12:28:48 -0700 | [diff] [blame] | 149 | impl Add<$i> for $i { |
| 150 | type Output = $i; |
| 151 | fn add(self, other: $i) -> $i { self + other } |
| 152 | } |
Mike Hommey | e2bfbc5 | 2018-04-05 11:40:06 +0900 | [diff] [blame] | 153 | impl Copy for $i {} |
| 154 | impl Clone for $i { |
| 155 | fn clone(&self) -> $i { loop {} } |
| 156 | } |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 157 | )*) |
| 158 | } |
Alex Crichton | 9029cfb | 2017-10-18 12:28:48 -0700 | [diff] [blame] | 159 | each_int!(impl_traits); |
Eduard-Mihai Burtescu | 974f7ba | 2017-01-03 00:29:27 +0200 | [diff] [blame] | 160 | |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 161 | pub mod mem { |
| 162 | pub fn size_of_val<T>(_: &T) -> usize { 4 } |
Bryant Mairs | 011ba6d | 2017-12-06 19:53:55 -0800 | [diff] [blame] | 163 | pub fn size_of<T>(_: &T) -> usize { 4 } |
Alex Crichton | 07d3a0d | 2015-10-30 10:21:32 -0700 | [diff] [blame] | 164 | } |
Alex Crichton | 24abc4f | 2015-09-16 23:54:56 -0700 | [diff] [blame] | 165 | } |