diff options
Diffstat (limited to 'crates/test_utils')
-rw-r--r-- | crates/test_utils/src/minicore.rs | 126 |
1 files changed, 121 insertions, 5 deletions
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 9ec541c57..ce6ad8541 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs | |||
@@ -15,14 +15,17 @@ | |||
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 |
27 | //! eq: sized | 30 | //! eq: sized |
28 | //! ord: eq, option | 31 | //! ord: eq, option |
@@ -40,6 +43,38 @@ pub mod marker { | |||
40 | #[lang = "unsize"] | 43 | #[lang = "unsize"] |
41 | pub trait Unsize<T: ?Sized> {} | 44 | pub trait Unsize<T: ?Sized> {} |
42 | // 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 | ||
43 | } | 78 | } |
44 | 79 | ||
45 | // region:default | 80 | // region:default |
@@ -50,6 +85,19 @@ pub mod default { | |||
50 | } | 85 | } |
51 | // endregion:default | 86 | // endregion:default |
52 | 87 | ||
88 | // region:clone | ||
89 | pub 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 | |||
53 | // region:from | 101 | // region:from |
54 | pub mod convert { | 102 | pub mod convert { |
55 | pub trait From<T>: Sized { | 103 | pub trait From<T>: Sized { |
@@ -114,9 +162,53 @@ pub mod ops { | |||
114 | } | 162 | } |
115 | // endregion:deref_mut | 163 | // endregion:deref_mut |
116 | } | 164 | } |
117 | pub use self::deref::Deref; | 165 | pub use self::deref::{ |
118 | pub use self::deref::DerefMut; //:deref_mut | 166 | Deref, |
119 | // 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 | ||
120 | 212 | ||
121 | // region:range | 213 | // region:range |
122 | mod range { | 214 | mod range { |
@@ -298,7 +390,6 @@ pub mod iter { | |||
298 | iter: I, | 390 | iter: I, |
299 | n: usize, | 391 | n: usize, |
300 | } | 392 | } |
301 | |||
302 | impl<I> Iterator for Take<I> | 393 | impl<I> Iterator for Take<I> |
303 | where | 394 | where |
304 | I: Iterator, | 395 | I: Iterator, |
@@ -309,6 +400,22 @@ pub mod iter { | |||
309 | loop {} | 400 | loop {} |
310 | } | 401 | } |
311 | } | 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 | } | ||
312 | } | 419 | } |
313 | pub use self::adapters::Take; | 420 | pub use self::adapters::Take; |
314 | 421 | ||
@@ -356,6 +463,13 @@ pub mod iter { | |||
356 | fn take(self, n: usize) -> crate::iter::Take<Self> { | 463 | fn take(self, n: usize) -> crate::iter::Take<Self> { |
357 | loop {} | 464 | loop {} |
358 | } | 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 | } | ||
359 | // endregion:iterators | 473 | // endregion:iterators |
360 | } | 474 | } |
361 | impl<I: Iterator + ?Sized> Iterator for &mut I { | 475 | impl<I: Iterator + ?Sized> Iterator for &mut I { |
@@ -402,12 +516,14 @@ mod macros { | |||
402 | pub mod prelude { | 516 | pub mod prelude { |
403 | pub mod v1 { | 517 | pub mod v1 { |
404 | pub use crate::{ | 518 | pub use crate::{ |
519 | clone::Clone, // :clone | ||
405 | cmp::{Eq, PartialEq}, // :eq | 520 | cmp::{Eq, PartialEq}, // :eq |
406 | cmp::{Ord, PartialOrd}, // :ord | 521 | cmp::{Ord, PartialOrd}, // :ord |
407 | convert::{From, Into}, // :from | 522 | convert::{From, Into}, // :from |
408 | default::Default, // :default | 523 | default::Default, // :default |
409 | iter::{IntoIterator, Iterator}, // :iterator | 524 | iter::{IntoIterator, Iterator}, // :iterator |
410 | macros::builtin::derive, // :derive | 525 | macros::builtin::derive, // :derive |
526 | marker::Copy, // :copy | ||
411 | marker::Sized, // :sized | 527 | marker::Sized, // :sized |
412 | ops::{Fn, FnMut, FnOnce}, // :fn | 528 | ops::{Fn, FnMut, FnOnce}, // :fn |
413 | option::Option::{self, None, Some}, // :option | 529 | option::Option::{self, None, Some}, // :option |