aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-15 19:34:26 +0100
committerAleksey Kladov <[email protected]>2021-06-15 19:34:26 +0100
commit7ebac5e54c51c6b8f1ddf3bb905f625416cc09fa (patch)
tree1eb45c7a221654c7da7ac3baebbb6deb02271593 /crates
parent047520153878ade5b0136bc151fc53a43419b1c9 (diff)
internal: switch some tests to minicore
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/tests/coercion.rs65
-rw-r--r--crates/hir_ty/src/tests/method_resolution.rs44
-rw-r--r--crates/test_utils/src/minicore.rs28
3 files changed, 75 insertions, 62 deletions
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs
index eca6ae1fe..713b74165 100644
--- a/crates/hir_ty/src/tests/coercion.rs
+++ b/crates/hir_ty/src/tests/coercion.rs
@@ -426,15 +426,15 @@ fn coerce_autoderef() {
426#[test] 426#[test]
427fn coerce_autoderef_generic() { 427fn coerce_autoderef_generic() {
428 check_infer_with_mismatches( 428 check_infer_with_mismatches(
429 r" 429 r#"
430 struct Foo; 430struct Foo;
431 fn takes_ref<T>(x: &T) -> T { *x } 431fn takes_ref<T>(x: &T) -> T { *x }
432 fn test() { 432fn test() {
433 takes_ref(&Foo); 433 takes_ref(&Foo);
434 takes_ref(&&Foo); 434 takes_ref(&&Foo);
435 takes_ref(&&&Foo); 435 takes_ref(&&&Foo);
436 } 436}
437 ", 437"#,
438 expect![[r" 438 expect![[r"
439 28..29 'x': &T 439 28..29 'x': &T
440 40..46 '{ *x }': T 440 40..46 '{ *x }': T
@@ -464,30 +464,29 @@ fn coerce_autoderef_generic() {
464fn coerce_autoderef_block() { 464fn coerce_autoderef_block() {
465 check_infer_with_mismatches( 465 check_infer_with_mismatches(
466 r#" 466 r#"
467 struct String {} 467//- minicore: deref
468 #[lang = "deref"] 468struct String {}
469 trait Deref { type Target; } 469impl core::ops::Deref for String { type Target = str; }
470 impl Deref for String { type Target = str; } 470fn takes_ref_str(x: &str) {}
471 fn takes_ref_str(x: &str) {} 471fn returns_string() -> String { loop {} }
472 fn returns_string() -> String { loop {} } 472fn test() {
473 fn test() { 473 takes_ref_str(&{ returns_string() });
474 takes_ref_str(&{ returns_string() }); 474}
475 } 475"#,
476 "#, 476 expect![[r#"
477 expect![[r" 477 90..91 'x': &str
478 126..127 'x': &str 478 99..101 '{}': ()
479 135..137 '{}': () 479 132..143 '{ loop {} }': String
480 168..179 '{ loop {} }': String 480 134..141 'loop {}': !
481 170..177 'loop {}': ! 481 139..141 '{}': ()
482 175..177 '{}': () 482 154..199 '{ ... }); }': ()
483 190..235 '{ ... }); }': () 483 160..173 'takes_ref_str': fn takes_ref_str(&str)
484 196..209 'takes_ref_str': fn takes_ref_str(&str) 484 160..196 'takes_...g() })': ()
485 196..232 'takes_...g() })': () 485 174..195 '&{ ret...ng() }': &String
486 210..231 '&{ ret...ng() }': &String 486 175..195 '{ retu...ng() }': String
487 211..231 '{ retu...ng() }': String 487 177..191 'returns_string': fn returns_string() -> String
488 213..227 'returns_string': fn returns_string() -> String 488 177..193 'return...ring()': String
489 213..229 'return...ring()': String 489 "#]],
490 "]],
491 ); 490 );
492} 491}
493 492
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs
index f26b2c8a7..79108054c 100644
--- a/crates/hir_ty/src/tests/method_resolution.rs
+++ b/crates/hir_ty/src/tests/method_resolution.rs
@@ -780,10 +780,7 @@ fn test() { (&S).foo(); }
780fn method_resolution_unsize_array() { 780fn method_resolution_unsize_array() {
781 check_types( 781 check_types(
782 r#" 782 r#"
783#[lang = "slice"] 783//- minicore: slice
784impl<T> [T] {
785 fn len(&self) -> usize { loop {} }
786}
787fn test() { 784fn test() {
788 let a = [1, 2, 3]; 785 let a = [1, 2, 3];
789 a.len(); 786 a.len();
@@ -1178,11 +1175,7 @@ fn main() {
1178fn autoderef_visibility_field() { 1175fn autoderef_visibility_field() {
1179 check_infer( 1176 check_infer(
1180 r#" 1177 r#"
1181#[lang = "deref"] 1178//- minicore: deref
1182pub trait Deref {
1183 type Target;
1184 fn deref(&self) -> &Self::Target;
1185}
1186mod a { 1179mod a {
1187 pub struct Foo(pub char); 1180 pub struct Foo(pub char);
1188 pub struct Bar(i32); 1181 pub struct Bar(i32);
@@ -1191,7 +1184,7 @@ mod a {
1191 Self(0) 1184 Self(0)
1192 } 1185 }
1193 } 1186 }
1194 impl super::Deref for Bar { 1187 impl core::ops::Deref for Bar {
1195 type Target = Foo; 1188 type Target = Foo;
1196 fn deref(&self) -> &Foo { 1189 fn deref(&self) -> &Foo {
1197 &Foo('z') 1190 &Foo('z')
@@ -1205,22 +1198,21 @@ mod b {
1205} 1198}
1206 "#, 1199 "#,
1207 expect![[r#" 1200 expect![[r#"
1208 67..71 'self': &Self 1201 107..138 '{ ... }': Bar
1209 200..231 '{ ... }': Bar 1202 121..125 'Self': Bar(i32) -> Bar
1210 214..218 'Self': Bar(i32) -> Bar 1203 121..128 'Self(0)': Bar
1211 214..221 'Self(0)': Bar 1204 126..127 '0': i32
1212 219..220 '0': i32 1205 226..230 'self': &Bar
1213 315..319 'self': &Bar 1206 240..273 '{ ... }': &Foo
1214 329..362 '{ ... }': &Foo 1207 254..263 '&Foo('z')': &Foo
1215 343..352 '&Foo('z')': &Foo 1208 255..258 'Foo': Foo(char) -> Foo
1216 344..347 'Foo': Foo(char) -> Foo 1209 255..263 'Foo('z')': Foo
1217 344..352 'Foo('z')': Foo 1210 259..262 ''z'': char
1218 348..351 ''z'': char 1211 303..350 '{ ... }': ()
1219 392..439 '{ ... }': () 1212 317..318 'x': char
1220 406..407 'x': char 1213 321..339 'super:...r::new': fn new() -> Bar
1221 410..428 'super:...r::new': fn new() -> Bar 1214 321..341 'super:...:new()': Bar
1222 410..430 'super:...:new()': Bar 1215 321..343 'super:...ew().0': char
1223 410..432 'super:...ew().0': char
1224 "#]], 1216 "#]],
1225 ) 1217 )
1226} 1218}
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 8f8f1c9f8..a61459f6d 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -9,7 +9,9 @@
9//! 9//!
10//! Available flags: 10//! Available flags:
11//! sized: 11//! sized:
12//! slice:
12//! unsize: sized 13//! unsize: sized
14//! deref: sized
13//! coerce_unsized: unsize 15//! coerce_unsized: unsize
14 16
15pub mod marker { 17pub mod marker {
@@ -27,8 +29,8 @@ pub mod marker {
27} 29}
28 30
29pub mod ops { 31pub mod ops {
32 // region:coerce_unsized
30 mod unsize { 33 mod unsize {
31 // region:coerce_unsized
32 use crate::marker::Unsize; 34 use crate::marker::Unsize;
33 35
34 #[lang = "coerce_unsized"] 36 #[lang = "coerce_unsized"]
@@ -45,11 +47,31 @@ pub mod ops {
45 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} 47 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
46 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {} 48 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
47 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {} 49 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
48 // endregion:coerce_unsized
49 } 50 }
51 pub use self::unsize::CoerceUnsized;
52 // endregion:coerce_unsized
50 53
51 pub use self::unsize::CoerceUnsized; // :coerce_unsized 54 // region:deref
55 mod deref {
56 #[lang = "deref"]
57 pub trait Deref {
58 #[lang = "deref_target"]
59 type Target: ?Sized;
60 fn deref(&self) -> &Self::Target;
61 }
62 }
63 pub use self::deref::Deref;
64 // endregion:deref
65}
66
67// region:slice
68pub mod slice {
69 #[lang = "slice"]
70 impl<T> [T] {
71 pub fn len(&self) -> usize { loop {} }
72 }
52} 73}
74// endregion:slice
53 75
54pub mod prelude { 76pub mod prelude {
55 pub mod v1 { 77 pub mod v1 {