aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-15 20:59:51 +0100
committerAleksey Kladov <[email protected]>2021-06-15 20:59:51 +0100
commit2870d2bade94ae276cba56caf8c35feaacd49422 (patch)
tree4f2e0f2f070d44d408d24a087d9fb9d06d499b6d /crates
parent3efe5c3426a311b6d617f9718b82e9a598dfa06d (diff)
internal: add option to minicore
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/tests/traits.rs46
-rw-r--r--crates/test_utils/src/fixture.rs2
-rw-r--r--crates/test_utils/src/minicore.rs18
3 files changed, 25 insertions, 41 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 33689e081..6df8181ed 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -26,25 +26,14 @@ fn test() {
26fn infer_async() { 26fn infer_async() {
27 check_types( 27 check_types(
28 r#" 28 r#"
29//- /main.rs crate:main deps:core 29//- minicore: future
30async fn foo() -> u64 { 30async fn foo() -> u64 { 128 }
31 128
32}
33 31
34fn test() { 32fn test() {
35 let r = foo(); 33 let r = foo();
36 let v = r.await; 34 let v = r.await;
37 v; 35 v;
38} //^ u64 36} //^ u64
39
40//- /core.rs crate:core
41#[prelude_import] use future::*;
42mod future {
43 #[lang = "future_trait"]
44 trait Future {
45 type Output;
46 }
47}
48"#, 37"#,
49 ); 38 );
50} 39}
@@ -53,24 +42,13 @@ mod future {
53fn infer_desugar_async() { 42fn infer_desugar_async() {
54 check_types( 43 check_types(
55 r#" 44 r#"
56//- /main.rs crate:main deps:core 45//- minicore: future
57async fn foo() -> u64 { 46async fn foo() -> u64 { 128 }
58 128
59}
60 47
61fn test() { 48fn test() {
62 let r = foo(); 49 let r = foo();
63 r; 50 r;
64} //^ impl Future<Output = u64> 51} //^ impl Future<Output = u64>
65
66//- /core.rs crate:core
67#[prelude_import] use future::*;
68mod future {
69 trait Future {
70 type Output;
71 }
72}
73
74"#, 52"#,
75 ); 53 );
76} 54}
@@ -79,7 +57,7 @@ mod future {
79fn infer_async_block() { 57fn infer_async_block() {
80 check_types( 58 check_types(
81 r#" 59 r#"
82//- /main.rs crate:main deps:core 60//- minicore: future, option
83async fn test() { 61async fn test() {
84 let a = async { 42 }; 62 let a = async { 42 };
85 a; 63 a;
@@ -91,7 +69,7 @@ async fn test() {
91 b; 69 b;
92// ^ () 70// ^ ()
93 let c = async { 71 let c = async {
94 let y = Option::None; 72 let y = None;
95 y 73 y
96 // ^ Option<u64> 74 // ^ Option<u64>
97 }; 75 };
@@ -99,18 +77,6 @@ async fn test() {
99 c; 77 c;
100// ^ impl Future<Output = Option<u64>> 78// ^ impl Future<Output = Option<u64>>
101} 79}
102
103enum Option<T> { None, Some(T) }
104
105//- /core.rs crate:core
106#[prelude_import] use future::*;
107mod future {
108 #[lang = "future_trait"]
109 trait Future {
110 type Output;
111 }
112}
113
114"#, 80"#,
115 ); 81 );
116} 82}
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 779146084..6ba112de8 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -198,6 +198,7 @@ impl MiniCore {
198 self.activated_flags.iter().any(|it| it == flag) 198 self.activated_flags.iter().any(|it| it == flag)
199 } 199 }
200 200
201 #[track_caller]
201 fn assert_valid_flag(&self, flag: &str) { 202 fn assert_valid_flag(&self, flag: &str) {
202 if !self.valid_flags.iter().any(|it| it == flag) { 203 if !self.valid_flags.iter().any(|it| it == flag) {
203 panic!("invalid flag: {:?}, valid flags: {:?}", flag, self.valid_flags); 204 panic!("invalid flag: {:?}, valid flags: {:?}", flag, self.valid_flags);
@@ -299,6 +300,7 @@ impl MiniCore {
299 let skip = if flag == "" { 300 let skip = if flag == "" {
300 false 301 false
301 } else { 302 } else {
303 assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag);
302 self.assert_valid_flag(flag); 304 self.assert_valid_flag(flag);
303 !self.has_flag(flag) 305 !self.has_flag(flag)
304 }; 306 };
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 127d06e59..cb18c8796 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -16,6 +16,7 @@
16//! coerce_unsized: unsize 16//! coerce_unsized: unsize
17//! pin: 17//! pin:
18//! future: pin 18//! future: pin
19//! option:
19 20
20pub mod marker { 21pub mod marker {
21 // region:sized 22 // region:sized
@@ -115,6 +116,17 @@ pub mod slice {
115} 116}
116// endregion:slice 117// endregion:slice
117 118
119// region:option
120pub mod option {
121 pub enum Option<T> {
122 #[lang = "None"]
123 None,
124 #[lang = "Some"]
125 Some(T),
126 }
127}
128// endregion:option
129
118// region:pin 130// region:pin
119pub mod pin { 131pub mod pin {
120 #[lang = "pin"] 132 #[lang = "pin"]
@@ -127,7 +139,10 @@ pub mod pin {
127 139
128// region:future 140// region:future
129pub mod future { 141pub mod future {
130 use crate::{pin::Pin, task::{Poll, Context}}; 142 use crate::{
143 pin::Pin,
144 task::{Context, Poll},
145 };
131 146
132 #[lang = "future_trait"] 147 #[lang = "future_trait"]
133 pub trait Future { 148 pub trait Future {
@@ -153,6 +168,7 @@ pub mod task {
153pub mod prelude { 168pub mod prelude {
154 pub mod v1 { 169 pub mod v1 {
155 pub use crate::marker::Sized; // :sized 170 pub use crate::marker::Sized; // :sized
171 pub use crate::option::Option::{self, None, Some}; // :option
156 } 172 }
157 173
158 pub mod rust_2015 { 174 pub mod rust_2015 {