internal: switch some tests to minicore

This commit is contained in:
Aleksey Kladov 2021-06-15 21:18:26 +03:00
parent f841369fee
commit 0475201538

View file

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