aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src/minicore.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils/src/minicore.rs')
-rw-r--r--crates/test_utils/src/minicore.rs188
1 files changed, 182 insertions, 6 deletions
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index a5a7c2f7d..ce6ad8541 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -15,15 +15,21 @@
15//! range: 15//! range:
16//! deref: sized 16//! deref: sized
17//! deref_mut: deref 17//! deref_mut: deref
18//! index: sized
18//! fn: 19//! fn:
19//! pin: 20//! pin:
20//! future: pin 21//! future: pin
21//! option: 22//! option:
22//! result: 23//! result:
23//! iterator: option 24//! iterator: option
24//! iterators: iterator 25//! iterators: iterator, fn
25//! default: sized 26//! default: sized
27//! clone: sized
28//! copy: clone
26//! from: sized 29//! from: sized
30//! eq: sized
31//! ord: eq, option
32//! derive:
27 33
28pub mod marker { 34pub mod marker {
29 // region:sized 35 // region:sized
@@ -37,6 +43,38 @@ pub mod marker {
37 #[lang = "unsize"] 43 #[lang = "unsize"]
38 pub trait Unsize<T: ?Sized> {} 44 pub trait Unsize<T: ?Sized> {}
39 // endregion:unsize 45 // endregion:unsize
46
47 // region:copy
48 #[lang = "copy"]
49 pub trait Copy: Clone {}
50 // region:derive
51 #[rustc_builtin_macro]
52 pub macro Copy($item:item) {}
53 // endregion:derive
54
55 mod copy_impls {
56 use super::Copy;
57
58 macro_rules! impl_copy {
59 ($($t:ty)*) => {
60 $(
61 impl Copy for $t {}
62 )*
63 }
64 }
65
66 impl_copy! {
67 usize u8 u16 u32 u64 u128
68 isize i8 i16 i32 i64 i128
69 f32 f64
70 bool char
71 }
72
73 impl<T: ?Sized> Copy for *const T {}
74 impl<T: ?Sized> Copy for *mut T {}
75 impl<T: ?Sized> Copy for &T {}
76 }
77 // endregion:copy
40} 78}
41 79
42// region:default 80// region:default
@@ -47,6 +85,19 @@ pub mod default {
47} 85}
48// endregion:default 86// endregion:default
49 87
88// region:clone
89pub mod clone {
90 #[lang = "clone"]
91 pub trait Clone: Sized {
92 fn clone(&self) -> Self;
93 }
94 // region:derive
95 #[rustc_builtin_macro]
96 pub macro Clone($item:item) {}
97 // endregion:derive
98}
99// endregion:clone
100
50// region:from 101// region:from
51pub mod convert { 102pub mod convert {
52 pub trait From<T>: Sized { 103 pub trait From<T>: Sized {
@@ -111,9 +162,53 @@ pub mod ops {
111 } 162 }
112 // endregion:deref_mut 163 // endregion:deref_mut
113 } 164 }
114 pub use self::deref::Deref; 165 pub use self::deref::{
115 pub use self::deref::DerefMut; //:deref_mut 166 Deref,
116 // endregion:deref 167 DerefMut, // :deref_mut
168 };
169 // endregion:deref
170
171 // region:index
172 mod index {
173 #[lang = "index"]
174 pub trait Index<Idx: ?Sized> {
175 type Output: ?Sized;
176 fn index(&self, index: Idx) -> &Self::Output;
177 }
178 #[lang = "index_mut"]
179 pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
180 fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
181 }
182
183 // region:slice
184 impl<T, I> Index<I> for [T]
185 where
186 I: SliceIndex<[T]>,
187 {
188 type Output = I::Output;
189 fn index(&self, index: I) -> &I::Output {
190 loop {}
191 }
192 }
193 impl<T, I> IndexMut<I> for [T]
194 where
195 I: SliceIndex<[T]>,
196 {
197 fn index_mut(&mut self, index: I) -> &mut I::Output {
198 loop {}
199 }
200 }
201
202 pub unsafe trait SliceIndex<T: ?Sized> {
203 type Output: ?Sized;
204 }
205 unsafe impl<T> SliceIndex<[T]> for usize {
206 type Output = T;
207 }
208 // endregion:slice
209 }
210 pub use self::index::{Index, IndexMut};
211 // endregion:index
117 212
118 // region:range 213 // region:range
119 mod range { 214 mod range {
@@ -173,6 +268,49 @@ pub mod ops {
173 // endregion:fn 268 // endregion:fn
174} 269}
175 270
271// region:eq
272pub mod cmp {
273 #[lang = "eq"]
274 pub trait PartialEq<Rhs: ?Sized = Self> {
275 fn eq(&self, other: &Rhs) -> bool;
276 }
277
278 pub trait Eq: PartialEq<Self> {}
279
280 // region:derive
281 #[rustc_builtin_macro]
282 pub macro PartialEq($item:item) {}
283 #[rustc_builtin_macro]
284 pub macro Eq($item:item) {}
285 // endregion:derive
286
287 // region:ord
288 #[lang = "partial_ord"]
289 pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
290 fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
291 }
292
293 pub trait Ord: Eq + PartialOrd<Self> {
294 fn cmp(&self, other: &Self) -> Ordering;
295 }
296
297 pub enum Ordering {
298 Less = -1,
299 Equal = 0,
300 Greater = 1,
301 }
302
303 // region:derive
304 #[rustc_builtin_macro]
305 pub macro PartialOrd($item:item) {}
306 #[rustc_builtin_macro]
307 pub macro Ord($item:item) {}
308 // endregion:derive
309
310 // endregion:ord
311}
312// endregion:eq
313
176// region:slice 314// region:slice
177pub mod slice { 315pub mod slice {
178 #[lang = "slice"] 316 #[lang = "slice"]
@@ -252,7 +390,6 @@ pub mod iter {
252 iter: I, 390 iter: I,
253 n: usize, 391 n: usize,
254 } 392 }
255
256 impl<I> Iterator for Take<I> 393 impl<I> Iterator for Take<I>
257 where 394 where
258 I: Iterator, 395 I: Iterator,
@@ -263,6 +400,22 @@ pub mod iter {
263 loop {} 400 loop {}
264 } 401 }
265 } 402 }
403
404 pub struct FilterMap<I, F> {
405 iter: I,
406 f: F,
407 }
408 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
409 where
410 F: FnMut(I::Item) -> Option<B>,
411 {
412 type Item = B;
413
414 #[inline]
415 fn next(&mut self) -> Option<B> {
416 loop {}
417 }
418 }
266 } 419 }
267 pub use self::adapters::Take; 420 pub use self::adapters::Take;
268 421
@@ -310,6 +463,13 @@ pub mod iter {
310 fn take(self, n: usize) -> crate::iter::Take<Self> { 463 fn take(self, n: usize) -> crate::iter::Take<Self> {
311 loop {} 464 loop {}
312 } 465 }
466 fn filter_map<B, F>(self, f: F) -> crate::iter::FilterMap<Self, F>
467 where
468 Self: Sized,
469 F: FnMut(Self::Item) -> Option<B>,
470 {
471 loop {}
472 }
313 // endregion:iterators 473 // endregion:iterators
314 } 474 }
315 impl<I: Iterator + ?Sized> Iterator for &mut I { 475 impl<I: Iterator + ?Sized> Iterator for &mut I {
@@ -342,16 +502,32 @@ pub mod iter {
342} 502}
343// endregion:iterator 503// endregion:iterator
344 504
505// region:derive
506mod macros {
507 pub(crate) mod builtin {
508 #[rustc_builtin_macro]
509 pub macro derive($item:item) {
510 /* compiler built-in */
511 }
512 }
513}
514// endregion:derive
515
345pub mod prelude { 516pub mod prelude {
346 pub mod v1 { 517 pub mod v1 {
347 pub use crate::{ 518 pub use crate::{
519 clone::Clone, // :clone
520 cmp::{Eq, PartialEq}, // :eq
521 cmp::{Ord, PartialOrd}, // :ord
522 convert::{From, Into}, // :from
348 default::Default, // :default 523 default::Default, // :default
349 iter::{IntoIterator, Iterator}, // :iterator 524 iter::{IntoIterator, Iterator}, // :iterator
525 macros::builtin::derive, // :derive
526 marker::Copy, // :copy
350 marker::Sized, // :sized 527 marker::Sized, // :sized
351 ops::{Fn, FnMut, FnOnce}, // :fn 528 ops::{Fn, FnMut, FnOnce}, // :fn
352 option::Option::{self, None, Some}, // :option 529 option::Option::{self, None, Some}, // :option
353 result::Result::{self, Err, Ok}, // :result 530 result::Result::{self, Err, Ok}, // :result
354 convert::{From, Into}, // :from
355 }; 531 };
356 } 532 }
357 533