blob: fbec3f2d4e6912ab708bd6fadf8da5a65858e335 [file] [log] [blame]
Alex Crichton24abc4f2015-09-16 23:54:56 -07001pub use self::imp::*;
2
3#[cfg(not(dox))]
4mod imp {
Alex Crichtonf7efe342015-11-02 14:26:04 -08005 pub use core::option::Option;
6 pub use core::clone::Clone;
7 pub use core::marker::Copy;
8 pub use core::mem;
Alex Crichton24abc4f2015-09-16 23:54:56 -07009}
10
11#[cfg(dox)]
12mod imp {
13 pub enum Option<T> {
14 Some(T),
15 None,
16 }
Alex Crichton0262b072015-09-17 17:53:03 -070017 impl<T: Copy> Copy for Option<T> {}
Alex Crichton97a2c172015-09-17 17:28:45 -070018 impl<T: Clone> Clone for Option<T> {
19 fn clone(&self) -> Option<T> { loop {} }
20 }
Alex Crichton24abc4f2015-09-16 23:54:56 -070021
22 pub trait Clone {
23 fn clone(&self) -> Self;
24 }
25
26 #[lang = "copy"]
27 pub trait Copy {}
28
Alex Crichton8dce9ad2015-12-03 11:44:14 -080029 #[lang = "sync"]
30 pub trait Sync {}
31 impl<T> Sync for T {}
32
Alex Crichton24abc4f2015-09-16 23:54:56 -070033 #[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 Burtescu974f7ba2017-01-03 00:29:27 +020043 each_signed_int!($mac);
44 )
45 }
46
47 macro_rules! each_signed_int {
48 ($mac:ident) => (
Alex Crichton24abc4f2015-09-16 23:54:56 -070049 $mac!(i8);
50 $mac!(i16);
51 $mac!(i32);
52 $mac!(i64);
53 $mac!(isize);
54 )
55 }
56
Alex Crichton07d3a0d2015-10-30 10:21:32 -070057 #[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 Crichton24abc4f2015-09-16 23:54:56 -070073 #[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 Crichton07d3a0d2015-10-30 10:21:32 -0700136
Eduard-Mihai Burtescu974f7ba2017-01-03 00:29:27 +0200137 #[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 Crichton07d3a0d2015-10-30 10:21:32 -0700169 pub mod mem {
170 pub fn size_of_val<T>(_: &T) -> usize { 4 }
171 }
Alex Crichton24abc4f2015-09-16 23:54:56 -0700172}