From 7ebac5e54c51c6b8f1ddf3bb905f625416cc09fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jun 2021 21:34:26 +0300 Subject: [PATCH] internal: switch some tests to minicore --- crates/hir_ty/src/tests/coercion.rs | 65 ++++++++++---------- crates/hir_ty/src/tests/method_resolution.rs | 44 ++++++------- crates/test_utils/src/minicore.rs | 28 ++++++++- 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 eca6ae1fe85..713b74165c1 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -426,15 +426,15 @@ fn test() { #[test] fn coerce_autoderef_generic() { check_infer_with_mismatches( - r" - struct Foo; - fn takes_ref(x: &T) -> T { *x } - fn test() { - takes_ref(&Foo); - takes_ref(&&Foo); - takes_ref(&&&Foo); - } - ", + r#" +struct Foo; +fn takes_ref(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 + "#]], ); } diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index f26b2c8a79c..79108054c1b 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs @@ -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] { - 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 "#]], ) } diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 8f8f1c9f8b5..a61459f6d93 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -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 {} } 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: ?Sized> CoerceUnsized<*const U> for &'a T {} impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} impl, U: ?Sized> CoerceUnsized<*const U> for *mut T {} impl, 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] { + pub fn len(&self) -> usize { loop {} } + } } +// endregion:slice pub mod prelude { pub mod v1 { -- 2.44.0