aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-15 19:11:53 +0100
committerAleksey Kladov <[email protected]>2021-06-15 19:11:53 +0100
commitf841369fee0f49125c83046340b228b032ebc702 (patch)
treec165c15099a73638f6082a5c3ceef62654cdcc0a /crates
parentf521e4185323699cd5d063b2704367a319583982 (diff)
internal: switch some tests to minicore
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/tests/coercion.rs197
-rw-r--r--crates/test_utils/src/minicore.rs9
2 files changed, 88 insertions, 118 deletions
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs
index 91236e974..58d454a0f 100644
--- a/crates/hir_ty/src/tests/coercion.rs
+++ b/crates/hir_ty/src/tests/coercion.rs
@@ -122,60 +122,52 @@ fn infer_let_stmt_coerce() {
122fn infer_custom_coerce_unsized() { 122fn infer_custom_coerce_unsized() {
123 check_infer( 123 check_infer(
124 r#" 124 r#"
125 struct A<T: ?Sized>(*const T); 125//- minicore: coerce_unsized
126 struct B<T: ?Sized>(*const T); 126use core::{marker::Unsize, ops::CoerceUnsized};
127 struct C<T: ?Sized> { inner: *const T }
128
129 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {}
130 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {}
131 127
132 fn foo1<T>(x: A<[T]>) -> A<[T]> { x } 128struct A<T: ?Sized>(*const T);
133 fn foo2<T>(x: B<[T]>) -> B<[T]> { x } 129struct B<T: ?Sized>(*const T);
134 fn foo3<T>(x: C<[T]>) -> C<[T]> { x } 130struct C<T: ?Sized> { inner: *const T }
135 131
136 fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) { 132impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {}
137 let d = foo1(a); 133impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {}
138 let e = foo2(b);
139 let f = foo3(c);
140 }
141 134
135fn foo1<T>(x: A<[T]>) -> A<[T]> { x }
136fn foo2<T>(x: B<[T]>) -> B<[T]> { x }
137fn foo3<T>(x: C<[T]>) -> C<[T]> { x }
142 138
143 #[lang = "sized"] 139fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) {
144 pub trait Sized {} 140 let d = foo1(a);
145 #[lang = "unsize"] 141 let e = foo2(b);
146 pub trait Unsize<T: ?Sized> {} 142 let f = foo3(c);
147 #[lang = "coerce_unsized"] 143}
148 pub trait CoerceUnsized<T> {} 144"#,
149
150 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
151 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
152 "#,
153 expect![[r#" 145 expect![[r#"
154 257..258 'x': A<[T]> 146 306..307 'x': A<[T]>
155 278..283 '{ x }': A<[T]> 147 327..332 '{ x }': A<[T]>
156 280..281 'x': A<[T]> 148 329..330 'x': A<[T]>
157 295..296 'x': B<[T]> 149 344..345 'x': B<[T]>
158 316..321 '{ x }': B<[T]> 150 365..370 '{ x }': B<[T]>
159 318..319 'x': B<[T]> 151 367..368 'x': B<[T]>
160 333..334 'x': C<[T]> 152 382..383 'x': C<[T]>
161 354..359 '{ x }': C<[T]> 153 403..408 '{ x }': C<[T]>
162 356..357 'x': C<[T]> 154 405..406 'x': C<[T]>
163 369..370 'a': A<[u8; 2]> 155 418..419 'a': A<[u8; 2]>
164 384..385 'b': B<[u8; 2]> 156 433..434 'b': B<[u8; 2]>
165 399..400 'c': C<[u8; 2]> 157 448..449 'c': C<[u8; 2]>
166 414..480 '{ ...(c); }': () 158 463..529 '{ ...(c); }': ()
167 424..425 'd': A<[{unknown}]> 159 473..474 'd': A<[{unknown}]>
168 428..432 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]> 160 477..481 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]>
169 428..435 'foo1(a)': A<[{unknown}]> 161 477..484 'foo1(a)': A<[{unknown}]>
170 433..434 'a': A<[u8; 2]> 162 482..483 'a': A<[u8; 2]>
171 445..446 'e': B<[u8]> 163 494..495 'e': B<[u8]>
172 449..453 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]> 164 498..502 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]>
173 449..456 'foo2(b)': B<[u8]> 165 498..505 'foo2(b)': B<[u8]>
174 454..455 'b': B<[u8; 2]> 166 503..504 'b': B<[u8; 2]>
175 466..467 'f': C<[u8]> 167 515..516 'f': C<[u8]>
176 470..474 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]> 168 519..523 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]>
177 470..477 'foo3(c)': C<[u8]> 169 519..526 'foo3(c)': C<[u8]>
178 475..476 'c': C<[u8; 2]> 170 524..525 'c': C<[u8; 2]>
179 "#]], 171 "#]],
180 ); 172 );
181} 173}
@@ -184,21 +176,16 @@ fn infer_custom_coerce_unsized() {
184fn infer_if_coerce() { 176fn infer_if_coerce() {
185 check_infer( 177 check_infer(
186 r#" 178 r#"
187 fn foo<T>(x: &[T]) -> &[T] { loop {} } 179//- minicore: unsize
188 fn test() { 180fn foo<T>(x: &[T]) -> &[T] { loop {} }
189 let x = if true { 181fn test() {
190 foo(&[1]) 182 let x = if true {
191 } else { 183 foo(&[1])
192 &[1] 184 } else {
193 }; 185 &[1]
194 } 186 };
195 187}
196 188"#,
197 #[lang = "sized"]
198 pub trait Sized {}
199 #[lang = "unsize"]
200 pub trait Unsize<T: ?Sized> {}
201 "#,
202 expect![[r#" 189 expect![[r#"
203 10..11 'x': &[T] 190 10..11 'x': &[T]
204 27..38 '{ loop {} }': &[T] 191 27..38 '{ loop {} }': &[T]
@@ -226,25 +213,16 @@ fn infer_if_coerce() {
226fn infer_if_else_coerce() { 213fn infer_if_else_coerce() {
227 check_infer( 214 check_infer(
228 r#" 215 r#"
229 fn foo<T>(x: &[T]) -> &[T] { loop {} } 216//- minicore: coerce_unsized
230 fn test() { 217fn foo<T>(x: &[T]) -> &[T] { loop {} }
231 let x = if true { 218fn test() {
232 &[1] 219 let x = if true {
233 } else { 220 &[1]
234 foo(&[1]) 221 } else {
235 }; 222 foo(&[1])
236 } 223 };
237 224}
238 #[lang = "sized"] 225"#,
239 pub trait Sized {}
240 #[lang = "unsize"]
241 pub trait Unsize<T: ?Sized> {}
242 #[lang = "coerce_unsized"]
243 pub trait CoerceUnsized<T> {}
244
245 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
246 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
247 "#,
248 expect![[r#" 226 expect![[r#"
249 10..11 'x': &[T] 227 10..11 'x': &[T]
250 27..38 '{ loop {} }': &[T] 228 27..38 '{ loop {} }': &[T]
@@ -272,20 +250,16 @@ fn infer_if_else_coerce() {
272fn infer_match_first_coerce() { 250fn infer_match_first_coerce() {
273 check_infer( 251 check_infer(
274 r#" 252 r#"
275 fn foo<T>(x: &[T]) -> &[T] { loop {} } 253//- minicore: unsize
276 fn test(i: i32) { 254fn foo<T>(x: &[T]) -> &[T] { loop {} }
277 let x = match i { 255fn test(i: i32) {
278 2 => foo(&[2]), 256 let x = match i {
279 1 => &[1], 257 2 => foo(&[2]),
280 _ => &[3], 258 1 => &[1],
281 }; 259 _ => &[3],
282 } 260 };
283 261}
284 #[lang = "sized"] 262"#,
285 pub trait Sized {}
286 #[lang = "unsize"]
287 pub trait Unsize<T: ?Sized> {}
288 "#,
289 expect![[r#" 263 expect![[r#"
290 10..11 'x': &[T] 264 10..11 'x': &[T]
291 27..38 '{ loop {} }': &[T] 265 27..38 '{ loop {} }': &[T]
@@ -320,25 +294,16 @@ fn infer_match_first_coerce() {
320fn infer_match_second_coerce() { 294fn infer_match_second_coerce() {
321 check_infer( 295 check_infer(
322 r#" 296 r#"
323 fn foo<T>(x: &[T]) -> &[T] { loop {} } 297//- minicore: coerce_unsized
324 fn test(i: i32) { 298fn foo<T>(x: &[T]) -> &[T] { loop {} }
325 let x = match i { 299fn test(i: i32) {
326 1 => &[1], 300 let x = match i {
327 2 => foo(&[2]), 301 1 => &[1],
328 _ => &[3], 302 2 => foo(&[2]),
329 }; 303 _ => &[3],
330 } 304 };
331 305}
332 #[lang = "sized"] 306"#,
333 pub trait Sized {}
334 #[lang = "unsize"]
335 pub trait Unsize<T: ?Sized> {}
336 #[lang = "coerce_unsized"]
337 pub trait CoerceUnsized<T> {}
338
339 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
340 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
341 "#,
342 expect![[r#" 307 expect![[r#"
343 10..11 'x': &[T] 308 10..11 'x': &[T]
344 27..38 '{ loop {} }': &[T] 309 27..38 '{ loop {} }': &[T]
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 629c06ed0..8f8f1c9f8 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -9,7 +9,8 @@
9//! 9//!
10//! Available flags: 10//! Available flags:
11//! sized: 11//! sized:
12//! coerce_unsized: sized 12//! unsize: sized
13//! coerce_unsized: unsize
13 14
14pub mod marker { 15pub mod marker {
15 // region:sized 16 // region:sized
@@ -17,10 +18,12 @@ pub mod marker {
17 #[fundamental] 18 #[fundamental]
18 #[rustc_specialization_trait] 19 #[rustc_specialization_trait]
19 pub trait Sized {} 20 pub trait Sized {}
21 // endregion:sized
20 22
23 // region:unsize
21 #[lang = "unsize"] 24 #[lang = "unsize"]
22 pub trait Unsize<T: ?Sized> {} 25 pub trait Unsize<T: ?Sized> {}
23 // endregion:sized 26 // endregion:unsize
24} 27}
25 28
26pub mod ops { 29pub mod ops {
@@ -44,6 +47,8 @@ pub mod ops {
44 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {} 47 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
45 // endregion:coerce_unsized 48 // endregion:coerce_unsized
46 } 49 }
50
51 pub use self::unsize::CoerceUnsized; // :coerce_unsized
47} 52}
48 53
49pub mod prelude { 54pub mod prelude {