aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/tests/coercion.rs77
1 files changed, 62 insertions, 15 deletions
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs
index 7e9fc8735..6dac7e103 100644
--- a/crates/hir_ty/src/tests/coercion.rs
+++ b/crates/hir_ty/src/tests/coercion.rs
@@ -832,11 +832,9 @@ fn coerce_unsize_super_trait_cycle() {
832 ); 832 );
833} 833}
834 834
835#[ignore]
836#[test] 835#[test]
837fn coerce_unsize_generic() { 836fn coerce_unsize_generic() {
838 // FIXME: Implement this 837 // FIXME: fix the type mismatches here
839 // https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions
840 check_infer_with_mismatches( 838 check_infer_with_mismatches(
841 r#" 839 r#"
842 #[lang = "unsize"] 840 #[lang = "unsize"]
@@ -854,8 +852,58 @@ fn coerce_unsize_generic() {
854 let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); 852 let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
855 } 853 }
856 "#, 854 "#,
857 expect![[r" 855 expect![[r#"
858 "]], 856 209..317 '{ ... }); }': ()
857 219..220 '_': &Foo<[usize]>
858 238..259 '&Foo {..., 3] }': &Foo<[usize]>
859 239..259 'Foo { ..., 3] }': Foo<[usize]>
860 248..257 '[1, 2, 3]': [usize; 3]
861 249..250 '1': usize
862 252..253 '2': usize
863 255..256 '3': usize
864 269..270 '_': &Bar<[usize]>
865 288..314 '&Bar(F... 3] })': &Bar<[i32; 3]>
866 289..292 'Bar': Bar<[i32; 3]>(Foo<[i32; 3]>) -> Bar<[i32; 3]>
867 289..314 'Bar(Fo... 3] })': Bar<[i32; 3]>
868 293..313 'Foo { ..., 3] }': Foo<[i32; 3]>
869 302..311 '[1, 2, 3]': [i32; 3]
870 303..304 '1': i32
871 306..307 '2': i32
872 309..310 '3': i32
873 248..257: expected [usize], got [usize; 3]
874 288..314: expected &Bar<[usize]>, got &Bar<[i32; 3]>
875 "#]],
876 );
877}
878
879#[test]
880fn coerce_unsize_apit() {
881 // FIXME: #8984
882 check_infer_with_mismatches(
883 r#"
884#[lang = "sized"]
885pub trait Sized {}
886#[lang = "unsize"]
887pub trait Unsize<T> {}
888#[lang = "coerce_unsized"]
889pub trait CoerceUnsized<T> {}
890
891impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {}
892
893trait Foo {}
894
895fn test(f: impl Foo) {
896 let _: &dyn Foo = &f;
897}
898 "#,
899 expect![[r#"
900 210..211 'f': impl Foo
901 223..252 '{ ... &f; }': ()
902 233..234 '_': &dyn Foo
903 247..249 '&f': &impl Foo
904 248..249 'f': impl Foo
905 247..249: expected &dyn Foo, got &impl Foo
906 "#]],
859 ); 907 );
860} 908}
861 909
@@ -921,7 +969,7 @@ mod panic {
921 #[macro_export] 969 #[macro_export]
922 pub macro panic_2015 { 970 pub macro panic_2015 {
923 () => ( 971 () => (
924 $crate::panicking::panic("explicit panic") 972 $crate::panicking::panic()
925 ), 973 ),
926 } 974 }
927} 975}
@@ -940,19 +988,18 @@ macro_rules! panic {
940} 988}
941 989
942fn main() { 990fn main() {
943 panic!("internal error: entered unreachable code") 991 panic!()
944} 992}
945 "#, 993 "#,
946 expect![[r#" 994 expect![[r#"
947 190..201 '{ loop {} }': ! 995 174..185 '{ loop {} }': !
948 192..199 'loop {}': ! 996 176..183 'loop {}': !
949 197..199 '{}': () 997 181..183 '{}': ()
950 !0..24 '$crate...:panic': fn panic() -> ! 998 !0..24 '$crate...:panic': fn panic() -> !
951 !0..42 '$crate...anic")': ! 999 !0..26 '$crate...anic()': !
952 !0..42 '$crate...anic")': ! 1000 !0..26 '$crate...anic()': !
953 !0..70 '$crate...code")': ! 1001 !0..28 '$crate...015!()': !
954 !25..41 '"expli...panic"': &str 1002 454..470 '{ ...c!() }': ()
955 470..528 '{ ...de") }': ()
956 "#]], 1003 "#]],
957 ); 1004 );
958} 1005}