blob: 1c93efe7086b63ad37d7aa416aef6f634726b04c [file] [log] [blame]
Alex Crichton24abc4f2015-09-16 23:54:56 -07001pub use self::imp::*;
2
Francis Gagné18341fd2018-03-18 14:09:07 -04003#[cfg(not(cross_platform_docs))]
Alex Crichton24abc4f2015-09-16 23:54:56 -07004mod 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
Francis Gagné18341fd2018-03-18 14:09:07 -040011#[cfg(cross_platform_docs)]
Alex Crichton24abc4f2015-09-16 23:54:56 -070012mod 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
Mike Hommeye2bfbc52018-04-05 11:40:06 +090022 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 Crichton24abc4f2015-09-16 23:54:56 -070032 pub trait Clone {
33 fn clone(&self) -> Self;
34 }
35
36 #[lang = "copy"]
37 pub trait Copy {}
38
Alex Crichtonc0cf2802017-05-25 16:06:01 -070039 #[lang = "freeze"]
40 pub trait Freeze {}
41
Alex Crichton8dce9ad2015-12-03 11:44:14 -080042 #[lang = "sync"]
43 pub trait Sync {}
44 impl<T> Sync for T {}
45
Alex Crichton24abc4f2015-09-16 23:54:56 -070046 #[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 Burtescu974f7ba2017-01-03 00:29:27 +020056 each_signed_int!($mac);
57 )
58 }
59
60 macro_rules! each_signed_int {
61 ($mac:ident) => (
Alex Crichton24abc4f2015-09-16 23:54:56 -070062 $mac!(i8);
63 $mac!(i16);
64 $mac!(i32);
65 $mac!(i64);
66 $mac!(isize);
67 )
68 }
69
Alex Crichton07d3a0d2015-10-30 10:21:32 -070070 #[lang = "div"]
71 pub trait Div<RHS> {
72 type Output;
73 fn div(self, rhs: RHS) -> Self::Output;
74 }
75
Alex Crichton24abc4f2015-09-16 23:54:56 -070076 #[lang = "shl"]
77 pub trait Shl<RHS> {
78 type Output;
79 fn shl(self, rhs: RHS) -> Self::Output;
80 }
81
Alex Crichton24abc4f2015-09-16 23:54:56 -070082 #[lang = "mul"]
83 pub trait Mul<RHS=Self> {
84 type Output;
85 fn mul(self, rhs: RHS) -> Self::Output;
86 }
87
Alex Crichton24abc4f2015-09-16 23:54:56 -070088 #[lang = "sub"]
89 pub trait Sub<RHS=Self> {
90 type Output;
91 fn sub(self, rhs: RHS) -> Self::Output;
92 }
93
Alex Crichton24abc4f2015-09-16 23:54:56 -070094 #[lang = "bitor"]
95 pub trait Bitor<RHS=Self> {
96 type Output;
97 fn bitor(self, rhs: RHS) -> Self::Output;
98 }
99
Eduard-Mihai Burtescu974f7ba2017-01-03 00:29:27 +0200100 #[lang = "neg"]
101 pub trait Neg {
102 type Output;
103 fn neg(self) -> Self::Output;
104 }
105
Eduard-Mihai Burtescu974f7ba2017-01-03 00:29:27 +0200106 #[lang = "not"]
107 pub trait Not {
108 type Output;
109 fn not(self) -> Self::Output;
110 }
111
Alex Crichton9029cfb2017-10-18 12:28:48 -0700112 #[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 Burtescu974f7ba2017-01-03 00:29:27 +0200119 ($($i:ident)*) => ($(
Alex Crichton9029cfb2017-10-18 12:28:48 -0700120 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 Burtescu974f7ba2017-01-03 00:29:27 +0200145 impl Not for $i {
146 type Output = $i;
147 fn not(self) -> $i { !self }
148 }
Alex Crichton9029cfb2017-10-18 12:28:48 -0700149 impl Add<$i> for $i {
150 type Output = $i;
151 fn add(self, other: $i) -> $i { self + other }
152 }
Mike Hommeye2bfbc52018-04-05 11:40:06 +0900153 impl Copy for $i {}
154 impl Clone for $i {
155 fn clone(&self) -> $i { loop {} }
156 }
Eduard-Mihai Burtescu974f7ba2017-01-03 00:29:27 +0200157 )*)
158 }
Alex Crichton9029cfb2017-10-18 12:28:48 -0700159 each_int!(impl_traits);
Eduard-Mihai Burtescu974f7ba2017-01-03 00:29:27 +0200160
Alex Crichton07d3a0d2015-10-30 10:21:32 -0700161 pub mod mem {
162 pub fn size_of_val<T>(_: &T) -> usize { 4 }
Bryant Mairs011ba6d2017-12-06 19:53:55 -0800163 pub fn size_of<T>(_: &T) -> usize { 4 }
Alex Crichton07d3a0d2015-10-30 10:21:32 -0700164 }
Alex Crichton24abc4f2015-09-16 23:54:56 -0700165}