]> git.lizzy.rs Git - rust.git/commitdiff
internal: switch some tests to minicore
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 15 Jun 2021 18:34:26 +0000 (21:34 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 15 Jun 2021 18:34:26 +0000 (21:34 +0300)
crates/hir_ty/src/tests/coercion.rs
crates/hir_ty/src/tests/method_resolution.rs
crates/test_utils/src/minicore.rs

index eca6ae1fe85c0f2f58f0bfd89559d55021b58db1..713b74165c1517a5186c5dfdec300d64e9b151fb 100644 (file)
@@ -426,15 +426,15 @@ fn test() {
 #[test]
 fn coerce_autoderef_generic() {
     check_infer_with_mismatches(
-        r"
-        struct Foo;
-        fn takes_ref<T>(x: &T) -> T { *x }
-        fn test() {
-            takes_ref(&Foo);
-            takes_ref(&&Foo);
-            takes_ref(&&&Foo);
-        }
-        ",
+        r#"
+struct Foo;
+fn takes_ref<T>(x: &T) -> T { *x }
+fn test() {
+    takes_ref(&Foo);
+    takes_ref(&&Foo);
+    takes_ref(&&&Foo);
+}
+"#,
         expect![[r"
             28..29 'x': &T
             40..46 '{ *x }': T
@@ -464,30 +464,29 @@ fn test() {
 fn coerce_autoderef_block() {
     check_infer_with_mismatches(
         r#"
-        struct String {}
-        #[lang = "deref"]
-        trait Deref { type Target; }
-        impl Deref for String { type Target = str; }
-        fn takes_ref_str(x: &str) {}
-        fn returns_string() -> String { loop {} }
-        fn test() {
-            takes_ref_str(&{ returns_string() });
-        }
-        "#,
-        expect![[r"
-            126..127 'x': &str
-            135..137 '{}': ()
-            168..179 '{ loop {} }': String
-            170..177 'loop {}': !
-            175..177 '{}': ()
-            190..235 '{     ... }); }': ()
-            196..209 'takes_ref_str': fn takes_ref_str(&str)
-            196..232 'takes_...g() })': ()
-            210..231 '&{ ret...ng() }': &String
-            211..231 '{ retu...ng() }': String
-            213..227 'returns_string': fn returns_string() -> String
-            213..229 'return...ring()': String
-        "]],
+//- minicore: deref
+struct String {}
+impl core::ops::Deref for String { type Target = str; }
+fn takes_ref_str(x: &str) {}
+fn returns_string() -> String { loop {} }
+fn test() {
+    takes_ref_str(&{ returns_string() });
+}
+"#,
+        expect![[r#"
+            90..91 'x': &str
+            99..101 '{}': ()
+            132..143 '{ loop {} }': String
+            134..141 'loop {}': !
+            139..141 '{}': ()
+            154..199 '{     ... }); }': ()
+            160..173 'takes_ref_str': fn takes_ref_str(&str)
+            160..196 'takes_...g() })': ()
+            174..195 '&{ ret...ng() }': &String
+            175..195 '{ retu...ng() }': String
+            177..191 'returns_string': fn returns_string() -> String
+            177..193 'return...ring()': String
+        "#]],
     );
 }
 
index f26b2c8a79c04641b04693ab2d8a5d899f4aa2b5..79108054c1b2891e05fa88d324811bfa28a1e448 100644 (file)
@@ -780,10 +780,7 @@ impl Trait for S { fn foo(self) -> u128 { 0 } }
 fn method_resolution_unsize_array() {
     check_types(
         r#"
-#[lang = "slice"]
-impl<T> [T] {
-    fn len(&self) -> usize { loop {} }
-}
+//- minicore: slice
 fn test() {
     let a = [1, 2, 3];
     a.len();
@@ -1178,11 +1175,7 @@ fn main() {
 fn autoderef_visibility_field() {
     check_infer(
         r#"
-#[lang = "deref"]
-pub trait Deref {
-    type Target;
-    fn deref(&self) -> &Self::Target;
-}
+//- minicore: deref
 mod a {
     pub struct Foo(pub char);
     pub struct Bar(i32);
@@ -1191,7 +1184,7 @@ pub fn new() -> Self {
             Self(0)
         }
     }
-    impl super::Deref for Bar {
+    impl core::ops::Deref for Bar {
         type Target = Foo;
         fn deref(&self) -> &Foo {
             &Foo('z')
@@ -1205,22 +1198,21 @@ fn foo() {
 }
         "#,
         expect![[r#"
-            67..71 'self': &Self
-            200..231 '{     ...     }': Bar
-            214..218 'Self': Bar(i32) -> Bar
-            214..221 'Self(0)': Bar
-            219..220 '0': i32
-            315..319 'self': &Bar
-            329..362 '{     ...     }': &Foo
-            343..352 '&Foo('z')': &Foo
-            344..347 'Foo': Foo(char) -> Foo
-            344..352 'Foo('z')': Foo
-            348..351 ''z'': char
-            392..439 '{     ...     }': ()
-            406..407 'x': char
-            410..428 'super:...r::new': fn new() -> Bar
-            410..430 'super:...:new()': Bar
-            410..432 'super:...ew().0': char
+            107..138 '{     ...     }': Bar
+            121..125 'Self': Bar(i32) -> Bar
+            121..128 'Self(0)': Bar
+            126..127 '0': i32
+            226..230 'self': &Bar
+            240..273 '{     ...     }': &Foo
+            254..263 '&Foo('z')': &Foo
+            255..258 'Foo': Foo(char) -> Foo
+            255..263 'Foo('z')': Foo
+            259..262 ''z'': char
+            303..350 '{     ...     }': ()
+            317..318 'x': char
+            321..339 'super:...r::new': fn new() -> Bar
+            321..341 'super:...:new()': Bar
+            321..343 'super:...ew().0': char
         "#]],
     )
 }
index 8f8f1c9f8b58553d085057397c98ab3d3920add2..a61459f6d9318f66b63774f7b062ac64b391a2f7 100644 (file)
@@ -9,7 +9,9 @@
 //!
 //! Available flags:
 //!     sized:
+//!     slice:
 //!     unsize: sized
+//!     deref: sized
 //!     coerce_unsized: unsize
 
 pub mod marker {
@@ -27,8 +29,8 @@ pub trait Unsize<T: ?Sized> {}
 }
 
 pub mod ops {
+    // region:coerce_unsized
     mod unsize {
-        // region:coerce_unsized
         use crate::marker::Unsize;
 
         #[lang = "coerce_unsized"]
@@ -45,11 +47,31 @@ impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
         impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
         impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
         impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
-        // endregion:coerce_unsized
     }
+    pub use self::unsize::CoerceUnsized;
+    // endregion:coerce_unsized
 
-    pub use self::unsize::CoerceUnsized; // :coerce_unsized
+    // region:deref
+    mod deref {
+        #[lang = "deref"]
+        pub trait Deref {
+            #[lang = "deref_target"]
+            type Target: ?Sized;
+            fn deref(&self) -> &Self::Target;
+        }
+    }
+    pub use self::deref::Deref;
+    // endregion:deref
+}
+
+// region:slice
+pub mod slice {
+    #[lang = "slice"]
+    impl<T> [T] {
+        pub fn len(&self) -> usize { loop {} }
+    }
 }
+// endregion:slice
 
 pub mod prelude {
     pub mod v1 {