From 047520153878ade5b0136bc151fc53a43419b1c9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jun 2021 21:18:26 +0300 Subject: internal: switch some tests to minicore --- crates/hir_ty/src/tests/coercion.rs | 310 +++++++++++++++--------------------- 1 file changed, 129 insertions(+), 181 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 58d454a0f..eca6ae1fe 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -630,25 +630,19 @@ fn coerce_placeholder_ref() { fn coerce_unsize_array() { check_infer_with_mismatches( r#" - #[lang = "unsize"] - pub trait Unsize {} - #[lang = "coerce_unsized"] - pub trait CoerceUnsized {} - - impl, U> CoerceUnsized<&U> for &T {} - - fn test() { - let f: &[usize] = &[1, 2, 3]; - } +//- minicore: coerce_unsized +fn test() { + let f: &[usize] = &[1, 2, 3]; +} "#, expect![[r#" - 161..198 '{ ... 3]; }': () - 171..172 'f': &[usize] - 185..195 '&[1, 2, 3]': &[usize; 3] - 186..195 '[1, 2, 3]': [usize; 3] - 187..188 '1': usize - 190..191 '2': usize - 193..194 '3': usize + 10..47 '{ ... 3]; }': () + 20..21 'f': &[usize] + 34..44 '&[1, 2, 3]': &[usize; 3] + 35..44 '[1, 2, 3]': [usize; 3] + 36..37 '1': usize + 39..40 '2': usize + 42..43 '3': usize "#]], ); } @@ -657,42 +651,34 @@ fn coerce_unsize_array() { fn coerce_unsize_trait_object_simple() { check_infer_with_mismatches( r#" - #[lang = "sized"] - pub trait Sized {} - #[lang = "unsize"] - pub trait Unsize {} - #[lang = "coerce_unsized"] - pub trait CoerceUnsized {} - - impl, U> CoerceUnsized<&U> for &T {} - - trait Foo {} - trait Bar: Foo {} - trait Baz: Bar {} +//- minicore: coerce_unsized +trait Foo {} +trait Bar: Foo {} +trait Baz: Bar {} - struct S; - impl Foo for S {} - impl Bar for S {} - impl Baz for S {} +struct S; +impl Foo for S {} +impl Bar for S {} +impl Baz for S {} - fn test() { - let obj: &dyn Baz = &S; - let obj: &dyn Bar<_, i8, i16> = &S; - let obj: &dyn Foo = &S; - } - "#, - expect![[r" - 424..539 '{ ... &S; }': () - 434..437 'obj': &dyn Baz - 459..461 '&S': &S - 460..461 'S': S - 471..474 'obj': &dyn Bar - 499..501 '&S': &S - 500..501 'S': S - 511..514 'obj': &dyn Foo - 534..536 '&S': &S - 535..536 'S': S - "]], +fn test() { + let obj: &dyn Baz = &S; + let obj: &dyn Bar<_, i8, i16> = &S; + let obj: &dyn Foo = &S; +} +"#, + expect![[r#" + 236..351 '{ ... &S; }': () + 246..249 'obj': &dyn Baz + 271..273 '&S': &S + 272..273 'S': S + 283..286 'obj': &dyn Bar + 311..313 '&S': &S + 312..313 'S': S + 323..326 'obj': &dyn Foo + 346..348 '&S': &S + 347..348 'S': S + "#]], ); } @@ -717,49 +703,41 @@ fn coerce_unsize_trait_object_to_trait_object() { // 602..606 'obj2': &dyn Baz check_infer_with_mismatches( r#" - #[lang = "sized"] - pub trait Sized {} - #[lang = "unsize"] - pub trait Unsize {} - #[lang = "coerce_unsized"] - pub trait CoerceUnsized {} - - impl, U> CoerceUnsized<&U> for &T {} - - trait Foo {} - trait Bar: Foo {} - trait Baz: Bar {} +//- minicore: coerce_unsized +trait Foo {} +trait Bar: Foo {} +trait Baz: Bar {} - struct S; - impl Foo for S {} - impl Bar for S {} - impl Baz for S {} +struct S; +impl Foo for S {} +impl Bar for S {} +impl Baz for S {} - fn test() { - let obj: &dyn Baz = &S; - let obj: &dyn Bar<_, _, _> = obj; - let obj: &dyn Foo<_, _> = obj; - let obj2: &dyn Baz = &S; - let _: &dyn Foo<_, _> = obj2; - } - "#, +fn test() { + let obj: &dyn Baz = &S; + let obj: &dyn Bar<_, _, _> = obj; + let obj: &dyn Foo<_, _> = obj; + let obj2: &dyn Baz = &S; + let _: &dyn Foo<_, _> = obj2; +} +"#, expect![[r#" - 424..609 '{ ...bj2; }': () - 434..437 'obj': &dyn Baz - 459..461 '&S': &S - 460..461 'S': S - 471..474 'obj': &dyn Bar<{unknown}, {unknown}, {unknown}> - 496..499 'obj': &dyn Baz - 509..512 'obj': &dyn Foo<{unknown}, {unknown}> - 531..534 'obj': &dyn Bar<{unknown}, {unknown}, {unknown}> - 544..548 'obj2': &dyn Baz - 570..572 '&S': &S - 571..572 'S': S - 582..583 '_': &dyn Foo<{unknown}, {unknown}> - 602..606 'obj2': &dyn Baz - 496..499: expected &dyn Bar<{unknown}, {unknown}, {unknown}>, got &dyn Baz - 531..534: expected &dyn Foo<{unknown}, {unknown}>, got &dyn Bar<{unknown}, {unknown}, {unknown}> - 602..606: expected &dyn Foo<{unknown}, {unknown}>, got &dyn Baz + 236..421 '{ ...bj2; }': () + 246..249 'obj': &dyn Baz + 271..273 '&S': &S + 272..273 'S': S + 283..286 'obj': &dyn Bar<{unknown}, {unknown}, {unknown}> + 308..311 'obj': &dyn Baz + 321..324 'obj': &dyn Foo<{unknown}, {unknown}> + 343..346 'obj': &dyn Bar<{unknown}, {unknown}, {unknown}> + 356..360 'obj2': &dyn Baz + 382..384 '&S': &S + 383..384 'S': S + 394..395 '_': &dyn Foo<{unknown}, {unknown}> + 414..418 'obj2': &dyn Baz + 308..311: expected &dyn Bar<{unknown}, {unknown}, {unknown}>, got &dyn Baz + 343..346: expected &dyn Foo<{unknown}, {unknown}>, got &dyn Bar<{unknown}, {unknown}, {unknown}> + 414..418: expected &dyn Foo<{unknown}, {unknown}>, got &dyn Baz "#]], ); } @@ -768,40 +746,32 @@ fn coerce_unsize_trait_object_to_trait_object() { fn coerce_unsize_super_trait_cycle() { check_infer_with_mismatches( r#" - #[lang = "sized"] - pub trait Sized {} - #[lang = "unsize"] - pub trait Unsize {} - #[lang = "coerce_unsized"] - pub trait CoerceUnsized {} - - impl, U> CoerceUnsized<&U> for &T {} - - trait A {} - trait B: C + A {} - trait C: B {} - trait D: C - - struct S; - impl A for S {} - impl B for S {} - impl C for S {} - impl D for S {} +//- minicore: coerce_unsized +trait A {} +trait B: C + A {} +trait C: B {} +trait D: C - fn test() { - let obj: &dyn D = &S; - let obj: &dyn A = &S; - } - "#, - expect![[r" - 328..383 '{ ... &S; }': () - 338..341 'obj': &dyn D - 352..354 '&S': &S - 353..354 'S': S - 364..367 'obj': &dyn A - 378..380 '&S': &S - 379..380 'S': S - "]], +struct S; +impl A for S {} +impl B for S {} +impl C for S {} +impl D for S {} + +fn test() { + let obj: &dyn D = &S; + let obj: &dyn A = &S; +} +"#, + expect![[r#" + 140..195 '{ ... &S; }': () + 150..153 'obj': &dyn D + 164..166 '&S': &S + 165..166 'S': S + 176..179 'obj': &dyn A + 190..192 '&S': &S + 191..192 'S': S + "#]], ); } @@ -810,41 +780,35 @@ fn coerce_unsize_generic() { // FIXME: fix the type mismatches here check_infer_with_mismatches( r#" - #[lang = "unsize"] - pub trait Unsize {} - #[lang = "coerce_unsized"] - pub trait CoerceUnsized {} - - impl, U> CoerceUnsized<&U> for &T {} - - struct Foo { t: T }; - struct Bar(Foo); +//- minicore: coerce_unsized +struct Foo { t: T }; +struct Bar(Foo); - fn test() { - let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; - let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); - } - "#, +fn test() { + let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; + let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); +} +"#, expect![[r#" - 209..317 '{ ... }); }': () - 219..220 '_': &Foo<[usize]> - 238..259 '&Foo {..., 3] }': &Foo<[usize]> - 239..259 'Foo { ..., 3] }': Foo<[usize]> - 248..257 '[1, 2, 3]': [usize; 3] - 249..250 '1': usize - 252..253 '2': usize - 255..256 '3': usize - 269..270 '_': &Bar<[usize]> - 288..314 '&Bar(F... 3] })': &Bar<[i32; 3]> - 289..292 'Bar': Bar<[i32; 3]>(Foo<[i32; 3]>) -> Bar<[i32; 3]> - 289..314 'Bar(Fo... 3] })': Bar<[i32; 3]> - 293..313 'Foo { ..., 3] }': Foo<[i32; 3]> - 302..311 '[1, 2, 3]': [i32; 3] - 303..304 '1': i32 - 306..307 '2': i32 - 309..310 '3': i32 - 248..257: expected [usize], got [usize; 3] - 288..314: expected &Bar<[usize]>, got &Bar<[i32; 3]> + 58..166 '{ ... }); }': () + 68..69 '_': &Foo<[usize]> + 87..108 '&Foo {..., 3] }': &Foo<[usize]> + 88..108 'Foo { ..., 3] }': Foo<[usize]> + 97..106 '[1, 2, 3]': [usize; 3] + 98..99 '1': usize + 101..102 '2': usize + 104..105 '3': usize + 118..119 '_': &Bar<[usize]> + 137..163 '&Bar(F... 3] })': &Bar<[i32; 3]> + 138..141 'Bar': Bar<[i32; 3]>(Foo<[i32; 3]>) -> Bar<[i32; 3]> + 138..163 'Bar(Fo... 3] })': Bar<[i32; 3]> + 142..162 'Foo { ..., 3] }': Foo<[i32; 3]> + 151..160 '[1, 2, 3]': [i32; 3] + 152..153 '1': i32 + 155..156 '2': i32 + 158..159 '3': i32 + 97..106: expected [usize], got [usize; 3] + 137..163: expected &Bar<[usize]>, got &Bar<[i32; 3]> "#]], ); } @@ -854,15 +818,7 @@ fn coerce_unsize_apit() { // FIXME: #8984 check_infer_with_mismatches( r#" -#[lang = "sized"] -pub trait Sized {} -#[lang = "unsize"] -pub trait Unsize {} -#[lang = "coerce_unsized"] -pub trait CoerceUnsized {} - -impl, U> CoerceUnsized<&U> for &T {} - +//- minicore: coerce_unsized trait Foo {} fn test(f: impl Foo) { @@ -870,12 +826,12 @@ fn test(f: impl Foo) { } "#, expect![[r#" - 210..211 'f': impl Foo - 223..252 '{ ... &f; }': () - 233..234 '_': &dyn Foo - 247..249 '&f': &impl Foo - 248..249 'f': impl Foo - 247..249: expected &dyn Foo, got &impl Foo + 22..23 'f': impl Foo + 35..64 '{ ... &f; }': () + 45..46 '_': &dyn Foo + 59..61 '&f': &impl Foo + 60..61 'f': impl Foo + 59..61: expected &dyn Foo, got &impl Foo "#]], ); } @@ -971,15 +927,7 @@ fn main() { fn coerce_unsize_expected_type() { check_no_mismatches( r#" -#[lang = "sized"] -pub trait Sized {} -#[lang = "unsize"] -pub trait Unsize {} -#[lang = "coerce_unsized"] -pub trait CoerceUnsized {} - -impl, U> CoerceUnsized<&U> for &T {} - +//- minicore: coerce_unsized fn main() { let foo: &[u32] = &[1, 2]; let foo: &[u32] = match true { -- cgit v1.2.3