Skip to content

Commit b250d5e

Browse files
Merge #8985
8985: minor: Minor test fixes / new tests r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
2 parents 4afc1b8 + c33ee36 commit b250d5e

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

crates/hir_ty/src/tests/coercion.rs

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -832,11 +832,9 @@ fn coerce_unsize_super_trait_cycle() {
832832
);
833833
}
834834

835-
#[ignore]
836835
#[test]
837836
fn coerce_unsize_generic() {
838-
// FIXME: Implement this
839-
// https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions
837+
// FIXME: fix the type mismatches here
840838
check_infer_with_mismatches(
841839
r#"
842840
#[lang = "unsize"]
@@ -854,8 +852,58 @@ fn coerce_unsize_generic() {
854852
let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
855853
}
856854
"#,
857-
expect![[r"
858-
"]],
855+
expect![[r#"
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]
880+
fn coerce_unsize_apit() {
881+
// FIXME: #8984
882+
check_infer_with_mismatches(
883+
r#"
884+
#[lang = "sized"]
885+
pub trait Sized {}
886+
#[lang = "unsize"]
887+
pub trait Unsize<T> {}
888+
#[lang = "coerce_unsized"]
889+
pub trait CoerceUnsized<T> {}
890+
891+
impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {}
892+
893+
trait Foo {}
894+
895+
fn 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+
"#]],
859907
);
860908
}
861909

@@ -921,7 +969,7 @@ mod panic {
921969
#[macro_export]
922970
pub macro panic_2015 {
923971
() => (
924-
$crate::panicking::panic("explicit panic")
972+
$crate::panicking::panic()
925973
),
926974
}
927975
}
@@ -940,19 +988,18 @@ macro_rules! panic {
940988
}
941989
942990
fn main() {
943-
panic!("internal error: entered unreachable code")
991+
panic!()
944992
}
945993
"#,
946994
expect![[r#"
947-
190..201 '{ loop {} }': !
948-
192..199 'loop {}': !
949-
197..199 '{}': ()
995+
174..185 '{ loop {} }': !
996+
176..183 'loop {}': !
997+
181..183 '{}': ()
950998
!0..24 '$crate...:panic': fn panic() -> !
951-
!0..42 '$crate...anic")': !
952-
!0..42 '$crate...anic")': !
953-
!0..70 '$crate...code")': !
954-
!25..41 '"expli...panic"': &str
955-
470..528 '{ ...de") }': ()
999+
!0..26 '$crate...anic()': !
1000+
!0..26 '$crate...anic()': !
1001+
!0..28 '$crate...015!()': !
1002+
454..470 '{ ...c!() }': ()
9561003
"#]],
9571004
);
9581005
}

0 commit comments

Comments
 (0)