aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-02-21 17:24:18 +0000
committerFlorian Diebold <[email protected]>2020-02-22 10:09:21 +0000
commitde39d221a15c0a146ed8adbdb1616692180948bb (patch)
treec88cddbadedb021365e518d68502e8c2f9c21077 /crates/ra_hir_ty/src/tests
parentbaf832d6d903afbc39e3a01c752a1aa5218c020e (diff)
Implement unsize coercion using proper trait solving
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs82
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]
553fn coerce_unsize_array() {
554 assert_snapshot!(
555 infer_with_mismatches(r#"
556#[lang = "unsize"]
557pub trait Unsize<T> {}
558#[lang = "coerce_unsized"]
559pub trait CoerceUnsized<T> {}
560
561impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {}
562
563fn 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]
581fn coerce_unsize_trait_object() {
582 assert_snapshot!(
583 infer_with_mismatches(r#"
584#[lang = "unsize"]
585pub trait Unsize<T> {}
586#[lang = "coerce_unsized"]
587pub trait CoerceUnsized<T> {}
588
589impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {}
590
591trait Foo {}
592trait Bar: Foo {}
593struct S;
594impl Foo for S {}
595impl Bar for S {}
596
597fn 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]
609fn 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"]
615pub trait Unsize<T> {}
616#[lang = "coerce_unsized"]
617pub trait CoerceUnsized<T> {}
618
619impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {}
620
621struct Foo<T> { t: T };
622struct Bar<T>(Foo<T>);
623
624fn 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}