aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/coercion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests/coercion.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs55
1 files changed, 51 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs
index 136d28a91..d7fb6a962 100644
--- a/crates/ra_hir_ty/src/tests/coercion.rs
+++ b/crates/ra_hir_ty/src/tests/coercion.rs
@@ -662,7 +662,53 @@ fn test() {
662} 662}
663 663
664#[test] 664#[test]
665fn coerce_unsize_trait_object() { 665fn coerce_unsize_trait_object_simple() {
666 assert_snapshot!(
667 infer_with_mismatches(r#"
668#[lang = "sized"]
669pub trait Sized {}
670#[lang = "unsize"]
671pub trait Unsize<T> {}
672#[lang = "coerce_unsized"]
673pub trait CoerceUnsized<T> {}
674
675impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {}
676
677trait Foo<T, U> {}
678trait Bar<U, T, X>: Foo<T, U> {}
679trait Baz<T, X>: Bar<usize, T, X> {}
680
681struct S<T, X>;
682impl<T, X> Foo<T, usize> for S<T, X> {}
683impl<T, X> Bar<usize, T, X> for S<T, X> {}
684impl<T, X> Baz<T, X> for S<T, X> {}
685
686fn test() {
687 let obj: &dyn Baz<i8, i16> = &S;
688 let obj: &dyn Bar<_, i8, i16> = &S;
689 let obj: &dyn Foo<i8, _> = &S;
690}
691"#, true),
692 @r###"
693 424..539 '{ ... &S; }': ()
694 434..437 'obj': &dyn Baz<i8, i16>
695 459..461 '&S': &S<i8, i16>
696 460..461 'S': S<i8, i16>
697 471..474 'obj': &dyn Bar<usize, i8, i16>
698 499..501 '&S': &S<i8, i16>
699 500..501 'S': S<i8, i16>
700 511..514 'obj': &dyn Foo<i8, usize>
701 534..536 '&S': &S<i8, {unknown}>
702 535..536 'S': S<i8, {unknown}>
703 "###
704 );
705}
706
707#[test]
708// The rust reference says this should be possible, but rustc doesn't implement
709// it. We used to support it, but Chalk doesn't.
710#[ignore]
711fn coerce_unsize_trait_object_to_trait_object() {
666 assert_snapshot!( 712 assert_snapshot!(
667 infer_with_mismatches(r#" 713 infer_with_mismatches(r#"
668#[lang = "sized"] 714#[lang = "sized"]
@@ -735,16 +781,17 @@ impl D for S {}
735 781
736fn test() { 782fn test() {
737 let obj: &dyn D = &S; 783 let obj: &dyn D = &S;
738 let obj: &dyn A = obj; 784 let obj: &dyn A = &S;
739} 785}
740"#, true), 786"#, true),
741 @r###" 787 @r###"
742 328..384 '{ ...obj; }': () 788 328..383 '{ ... &S; }': ()
743 338..341 'obj': &dyn D 789 338..341 'obj': &dyn D
744 352..354 '&S': &S 790 352..354 '&S': &S
745 353..354 'S': S 791 353..354 'S': S
746 364..367 'obj': &dyn A 792 364..367 'obj': &dyn A
747 378..381 'obj': &dyn D 793 378..380 '&S': &S
794 379..380 'S': S
748 "### 795 "###
749 ); 796 );
750} 797}