aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-12 16:26:08 +0000
committerLukas Wirth <[email protected]>2021-01-12 16:26:08 +0000
commite9e3ab549d5a73f85e19eed5b915d78870f8892c (patch)
tree10f8792c8b532bdd4854220f3656130407c6ec67
parent52fa926f005890f07dffc789c84c2be57a6bdccc (diff)
Move FamousDefs fixture out into its own file
-rw-r--r--crates/ide_db/src/helpers.rs89
-rw-r--r--crates/ide_db/src/helpers/famous_defs_fixture.rs119
2 files changed, 120 insertions, 88 deletions
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs
index e3e5670f1..c6763ae36 100644
--- a/crates/ide_db/src/helpers.rs
+++ b/crates/ide_db/src/helpers.rs
@@ -38,94 +38,7 @@ pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option<Cr
38 38
39#[allow(non_snake_case)] 39#[allow(non_snake_case)]
40impl FamousDefs<'_, '_> { 40impl FamousDefs<'_, '_> {
41 pub const FIXTURE: &'static str = r#"//- /libcore.rs crate:core 41 pub const FIXTURE: &'static str = include_str!("helpers/famous_defs_fixture.rs");
42pub mod convert {
43 pub trait From<T> {
44 fn from(t: T) -> Self;
45 }
46}
47
48pub mod default {
49 pub trait Default {
50 fn default() -> Self;
51 }
52}
53
54pub mod iter {
55 pub use self::traits::{collect::IntoIterator, iterator::Iterator};
56 mod traits {
57 pub(crate) mod iterator {
58 use crate::option::Option;
59 pub trait Iterator {
60 type Item;
61 fn next(&mut self) -> Option<Self::Item>;
62 fn by_ref(&mut self) -> &mut Self {
63 self
64 }
65 fn take(self, n: usize) -> crate::iter::Take<Self> {
66 crate::iter::Take { inner: self }
67 }
68 }
69
70 impl<I: Iterator> Iterator for &mut I {
71 type Item = I::Item;
72 fn next(&mut self) -> Option<I::Item> {
73 (**self).next()
74 }
75 }
76 }
77 pub(crate) mod collect {
78 pub trait IntoIterator {
79 type Item;
80 }
81 }
82 }
83
84 pub use self::sources::*;
85 pub(crate) mod sources {
86 use super::Iterator;
87 use crate::option::Option::{self, *};
88 pub struct Repeat<A> {
89 element: A,
90 }
91
92 pub fn repeat<T>(elt: T) -> Repeat<T> {
93 Repeat { element: elt }
94 }
95
96 impl<A> Iterator for Repeat<A> {
97 type Item = A;
98
99 fn next(&mut self) -> Option<A> {
100 None
101 }
102 }
103 }
104
105 pub use self::adapters::*;
106 pub(crate) mod adapters {
107 use super::Iterator;
108 use crate::option::Option::{self, *};
109 pub struct Take<I> { pub(crate) inner: I }
110 impl<I> Iterator for Take<I> where I: Iterator {
111 type Item = <I as Iterator>::Item;
112 fn next(&mut self) -> Option<<I as Iterator>::Item> {
113 None
114 }
115 }
116 }
117}
118
119pub mod option {
120 pub enum Option<T> { None, Some(T)}
121}
122
123pub mod prelude {
124 pub use crate::{convert::From, iter::{IntoIterator, Iterator}, option::Option::{self, *}, default::Default};
125}
126#[prelude_import]
127pub use prelude::*;
128"#;
129 42
130 pub fn core(&self) -> Option<Crate> { 43 pub fn core(&self) -> Option<Crate> {
131 self.find_crate("core") 44 self.find_crate("core")
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..f3d355861
--- /dev/null
+++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs
@@ -0,0 +1,119 @@
1//- /libcore.rs crate:core
2pub mod convert {
3 pub trait From<T> {
4 fn from(t: T) -> Self;
5 }
6}
7
8pub mod default {
9 pub trait Default {
10 fn default() -> Self;
11 }
12}
13
14pub mod iter {
15 pub use self::traits::{collect::IntoIterator, iterator::Iterator};
16 mod traits {
17 pub(crate) mod iterator {
18 use crate::option::Option;
19 pub trait Iterator {
20 type Item;
21 fn next(&mut self) -> Option<Self::Item>;
22 fn by_ref(&mut self) -> &mut Self {
23 self
24 }
25 fn take(self, n: usize) -> crate::iter::Take<Self> {
26 crate::iter::Take { inner: self }
27 }
28 }
29
30 impl<I: Iterator> Iterator for &mut I {
31 type Item = I::Item;
32 fn next(&mut self) -> Option<I::Item> {
33 (**self).next()
34 }
35 }
36 }
37 pub(crate) mod collect {
38 pub trait IntoIterator {
39 type Item;
40 }
41 }
42 }
43
44 pub use self::sources::*;
45 pub(crate) mod sources {
46 use super::Iterator;
47 use crate::option::Option::{self, *};
48 pub struct Repeat<A> {
49 element: A,
50 }
51
52 pub fn repeat<T>(elt: T) -> Repeat<T> {
53 Repeat { element: elt }
54 }
55
56 impl<A> Iterator for Repeat<A> {
57 type Item = A;
58
59 fn next(&mut self) -> Option<A> {
60 None
61 }
62 }
63 }
64
65 pub use self::adapters::*;
66 pub(crate) mod adapters {
67 use super::Iterator;
68 use crate::option::Option::{self, *};
69 pub struct Take<I> {
70 pub(crate) inner: I,
71 }
72 impl<I> Iterator for Take<I>
73 where
74 I: Iterator,
75 {
76 type Item = <I as Iterator>::Item;
77 fn next(&mut self) -> Option<<I as Iterator>::Item> {
78 None
79 }
80 }
81 }
82}
83
84pub mod ops {
85 #[lang = "fn"]
86 pub trait Fn<Args>: FnMut<Args> {
87 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
88 }
89
90 #[lang = "fn_mut"]
91 pub trait FnMut<Args>: FnOnce<Args> {
92 extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
93 }
94 #[lang = "fn_once"]
95 pub trait FnOnce<Args> {
96 #[lang = "fn_once_output"]
97 type Output;
98 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
99 }
100}
101
102pub mod option {
103 pub enum Option<T> {
104 None,
105 Some(T),
106 }
107}
108
109pub mod prelude {
110 pub use crate::{
111 convert::From,
112 default::Default,
113 iter::{IntoIterator, Iterator},
114 ops::{Fn, FnMut, FnOnce},
115 option::Option::{self, *},
116 };
117}
118#[prelude_import]
119pub use prelude::*;