diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests/coercion.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/coercion.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 42330b269..aa2dfb5f0 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs | |||
@@ -548,3 +548,85 @@ impl<TT> S<TT> { | |||
548 | "### | 548 | "### |
549 | ); | 549 | ); |
550 | } | 550 | } |
551 | |||
552 | #[test] | ||
553 | fn coerce_unsize_array() { | ||
554 | assert_snapshot!( | ||
555 | infer_with_mismatches(r#" | ||
556 | #[lang = "unsize"] | ||
557 | pub trait Unsize<T> {} | ||
558 | #[lang = "coerce_unsized"] | ||
559 | pub trait CoerceUnsized<T> {} | ||
560 | |||
561 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
562 | |||
563 | fn test() { | ||
564 | let f: &[usize] = &[1, 2, 3]; | ||
565 | } | ||
566 | "#, true), | ||
567 | @r###" | ||
568 | [162; 199) '{ ... 3]; }': () | ||
569 | [172; 173) 'f': &[usize] | ||
570 | [186; 196) '&[1, 2, 3]': &[usize; _] | ||
571 | [187; 196) '[1, 2, 3]': [usize; _] | ||
572 | [188; 189) '1': usize | ||
573 | [191; 192) '2': usize | ||
574 | [194; 195) '3': usize | ||
575 | "### | ||
576 | ); | ||
577 | } | ||
578 | |||
579 | #[ignore] | ||
580 | #[test] | ||
581 | fn coerce_unsize_trait_object() { | ||
582 | assert_snapshot!( | ||
583 | infer_with_mismatches(r#" | ||
584 | #[lang = "unsize"] | ||
585 | pub trait Unsize<T> {} | ||
586 | #[lang = "coerce_unsized"] | ||
587 | pub trait CoerceUnsized<T> {} | ||
588 | |||
589 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
590 | |||
591 | trait Foo {} | ||
592 | trait Bar: Foo {} | ||
593 | struct S; | ||
594 | impl Foo for S {} | ||
595 | impl Bar for S {} | ||
596 | |||
597 | fn test() { | ||
598 | let obj: &dyn Bar = &S; | ||
599 | let obj: &dyn Foo = obj; | ||
600 | } | ||
601 | "#, true), | ||
602 | @r###" | ||
603 | "### | ||
604 | ); | ||
605 | } | ||
606 | |||
607 | #[ignore] | ||
608 | #[test] | ||
609 | fn coerce_unsize_generic() { | ||
610 | // FIXME: Implement this | ||
611 | // https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions | ||
612 | assert_snapshot!( | ||
613 | infer_with_mismatches(r#" | ||
614 | #[lang = "unsize"] | ||
615 | pub trait Unsize<T> {} | ||
616 | #[lang = "coerce_unsized"] | ||
617 | pub trait CoerceUnsized<T> {} | ||
618 | |||
619 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
620 | |||
621 | struct Foo<T> { t: T }; | ||
622 | struct Bar<T>(Foo<T>); | ||
623 | |||
624 | fn test() { | ||
625 | let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; | ||
626 | let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); | ||
627 | } | ||
628 | "#, true), | ||
629 | @r###" | ||
630 | "### | ||
631 | ); | ||
632 | } | ||