diff options
Diffstat (limited to 'crates/ide_db/src/helpers')
-rw-r--r-- | crates/ide_db/src/helpers/famous_defs_fixture.rs | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs new file mode 100644 index 000000000..5e88de64d --- /dev/null +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs | |||
@@ -0,0 +1,120 @@ | |||
1 | //- /libcore.rs crate:core | ||
2 | //! Signatures of traits, types and functions from the core lib for use in tests. | ||
3 | pub mod convert { | ||
4 | pub trait From<T> { | ||
5 | fn from(t: T) -> Self; | ||
6 | } | ||
7 | } | ||
8 | |||
9 | pub mod default { | ||
10 | pub trait Default { | ||
11 | fn default() -> Self; | ||
12 | } | ||
13 | } | ||
14 | |||
15 | pub mod iter { | ||
16 | pub use self::traits::{collect::IntoIterator, iterator::Iterator}; | ||
17 | mod traits { | ||
18 | pub(crate) mod iterator { | ||
19 | use crate::option::Option; | ||
20 | pub trait Iterator { | ||
21 | type Item; | ||
22 | fn next(&mut self) -> Option<Self::Item>; | ||
23 | fn by_ref(&mut self) -> &mut Self { | ||
24 | self | ||
25 | } | ||
26 | fn take(self, n: usize) -> crate::iter::Take<Self> { | ||
27 | crate::iter::Take { inner: self } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | impl<I: Iterator> Iterator for &mut I { | ||
32 | type Item = I::Item; | ||
33 | fn next(&mut self) -> Option<I::Item> { | ||
34 | (**self).next() | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | pub(crate) mod collect { | ||
39 | pub trait IntoIterator { | ||
40 | type Item; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | pub use self::sources::*; | ||
46 | pub(crate) mod sources { | ||
47 | use super::Iterator; | ||
48 | use crate::option::Option::{self, *}; | ||
49 | pub struct Repeat<A> { | ||
50 | element: A, | ||
51 | } | ||
52 | |||
53 | pub fn repeat<T>(elt: T) -> Repeat<T> { | ||
54 | Repeat { element: elt } | ||
55 | } | ||
56 | |||
57 | impl<A> Iterator for Repeat<A> { | ||
58 | type Item = A; | ||
59 | |||
60 | fn next(&mut self) -> Option<A> { | ||
61 | None | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | pub use self::adapters::*; | ||
67 | pub(crate) mod adapters { | ||
68 | use super::Iterator; | ||
69 | use crate::option::Option::{self, *}; | ||
70 | pub struct Take<I> { | ||
71 | pub(crate) inner: I, | ||
72 | } | ||
73 | impl<I> Iterator for Take<I> | ||
74 | where | ||
75 | I: Iterator, | ||
76 | { | ||
77 | type Item = <I as Iterator>::Item; | ||
78 | fn next(&mut self) -> Option<<I as Iterator>::Item> { | ||
79 | None | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | |||
85 | pub mod ops { | ||
86 | #[lang = "fn"] | ||
87 | pub trait Fn<Args>: FnMut<Args> { | ||
88 | extern "rust-call" fn call(&self, args: Args) -> Self::Output; | ||
89 | } | ||
90 | |||
91 | #[lang = "fn_mut"] | ||
92 | pub trait FnMut<Args>: FnOnce<Args> { | ||
93 | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; | ||
94 | } | ||
95 | #[lang = "fn_once"] | ||
96 | pub trait FnOnce<Args> { | ||
97 | #[lang = "fn_once_output"] | ||
98 | type Output; | ||
99 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | pub mod option { | ||
104 | pub enum Option<T> { | ||
105 | None, | ||
106 | Some(T), | ||
107 | } | ||
108 | } | ||
109 | |||
110 | pub mod prelude { | ||
111 | pub use crate::{ | ||
112 | convert::From, | ||
113 | default::Default, | ||
114 | iter::{IntoIterator, Iterator}, | ||
115 | ops::{Fn, FnMut, FnOnce}, | ||
116 | option::Option::{self, *}, | ||
117 | }; | ||
118 | } | ||
119 | #[prelude_import] | ||
120 | pub use prelude::*; | ||