diff options
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r-- | crates/test_utils/src/minicore.rs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index e6d2301c7..9ec541c57 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs | |||
@@ -22,6 +22,11 @@ | |||
22 | //! result: | 22 | //! result: |
23 | //! iterator: option | 23 | //! iterator: option |
24 | //! iterators: iterator | 24 | //! iterators: iterator |
25 | //! default: sized | ||
26 | //! from: sized | ||
27 | //! eq: sized | ||
28 | //! ord: eq, option | ||
29 | //! derive: | ||
25 | 30 | ||
26 | pub mod marker { | 31 | pub mod marker { |
27 | // region:sized | 32 | // region:sized |
@@ -37,6 +42,40 @@ pub mod marker { | |||
37 | // endregion:unsize | 42 | // endregion:unsize |
38 | } | 43 | } |
39 | 44 | ||
45 | // region:default | ||
46 | pub mod default { | ||
47 | pub trait Default: Sized { | ||
48 | fn default() -> Self; | ||
49 | } | ||
50 | } | ||
51 | // endregion:default | ||
52 | |||
53 | // region:from | ||
54 | pub mod convert { | ||
55 | pub trait From<T>: Sized { | ||
56 | fn from(_: T) -> Self; | ||
57 | } | ||
58 | pub trait Into<T>: Sized { | ||
59 | fn into(self) -> T; | ||
60 | } | ||
61 | |||
62 | impl<T, U> Into<U> for T | ||
63 | where | ||
64 | U: From<T>, | ||
65 | { | ||
66 | fn into(self) -> U { | ||
67 | U::from(self) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | impl<T> From<T> for T { | ||
72 | fn from(t: T) -> T { | ||
73 | t | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | // endregion:from | ||
78 | |||
40 | pub mod ops { | 79 | pub mod ops { |
41 | // region:coerce_unsized | 80 | // region:coerce_unsized |
42 | mod unsize { | 81 | mod unsize { |
@@ -137,6 +176,49 @@ pub mod ops { | |||
137 | // endregion:fn | 176 | // endregion:fn |
138 | } | 177 | } |
139 | 178 | ||
179 | // region:eq | ||
180 | pub mod cmp { | ||
181 | #[lang = "eq"] | ||
182 | pub trait PartialEq<Rhs: ?Sized = Self> { | ||
183 | fn eq(&self, other: &Rhs) -> bool; | ||
184 | } | ||
185 | |||
186 | pub trait Eq: PartialEq<Self> {} | ||
187 | |||
188 | // region:derive | ||
189 | #[rustc_builtin_macro] | ||
190 | pub macro PartialEq($item:item) {} | ||
191 | #[rustc_builtin_macro] | ||
192 | pub macro Eq($item:item) {} | ||
193 | // endregion:derive | ||
194 | |||
195 | // region:ord | ||
196 | #[lang = "partial_ord"] | ||
197 | pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { | ||
198 | fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>; | ||
199 | } | ||
200 | |||
201 | pub trait Ord: Eq + PartialOrd<Self> { | ||
202 | fn cmp(&self, other: &Self) -> Ordering; | ||
203 | } | ||
204 | |||
205 | pub enum Ordering { | ||
206 | Less = -1, | ||
207 | Equal = 0, | ||
208 | Greater = 1, | ||
209 | } | ||
210 | |||
211 | // region:derive | ||
212 | #[rustc_builtin_macro] | ||
213 | pub macro PartialOrd($item:item) {} | ||
214 | #[rustc_builtin_macro] | ||
215 | pub macro Ord($item:item) {} | ||
216 | // endregion:derive | ||
217 | |||
218 | // endregion:ord | ||
219 | } | ||
220 | // endregion:eq | ||
221 | |||
140 | // region:slice | 222 | // region:slice |
141 | pub mod slice { | 223 | pub mod slice { |
142 | #[lang = "slice"] | 224 | #[lang = "slice"] |
@@ -306,10 +388,26 @@ pub mod iter { | |||
306 | } | 388 | } |
307 | // endregion:iterator | 389 | // endregion:iterator |
308 | 390 | ||
391 | // region:derive | ||
392 | mod macros { | ||
393 | pub(crate) mod builtin { | ||
394 | #[rustc_builtin_macro] | ||
395 | pub macro derive($item:item) { | ||
396 | /* compiler built-in */ | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | // endregion:derive | ||
401 | |||
309 | pub mod prelude { | 402 | pub mod prelude { |
310 | pub mod v1 { | 403 | pub mod v1 { |
311 | pub use crate::{ | 404 | pub use crate::{ |
405 | cmp::{Eq, PartialEq}, // :eq | ||
406 | cmp::{Ord, PartialOrd}, // :ord | ||
407 | convert::{From, Into}, // :from | ||
408 | default::Default, // :default | ||
312 | iter::{IntoIterator, Iterator}, // :iterator | 409 | iter::{IntoIterator, Iterator}, // :iterator |
410 | macros::builtin::derive, // :derive | ||
313 | marker::Sized, // :sized | 411 | marker::Sized, // :sized |
314 | ops::{Fn, FnMut, FnOnce}, // :fn | 412 | ops::{Fn, FnMut, FnOnce}, // :fn |
315 | option::Option::{self, None, Some}, // :option | 413 | option::Option::{self, None, Some}, // :option |