Unnamed repository; edit this file 'description' to name the repository.
fix
Added the regression test unsized_from_keeps_type_info that builds minimal MyBox/MyRc stand-ins with CoerceUnsized + From to mirror the original Rc::from(Box<[i32]>) scenario and assert that the inferred type for rc stays MyRc<[i32]>. The fixture uses only minicore pieces (coerce_unsized, from) so it exercises the unsized coercion path entirely within the test harness, ensuring we’ll catch future regressions without needing real Box/Rc.
Asuka Minato 5 months ago
parent eaaa2da · commit 0ecb3f0
-rw-r--r--crates/hir-ty/src/tests/coercion.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/hir-ty/src/tests/coercion.rs b/crates/hir-ty/src/tests/coercion.rs
index 50aca16365..36630ab587 100644
--- a/crates/hir-ty/src/tests/coercion.rs
+++ b/crates/hir-ty/src/tests/coercion.rs
@@ -88,6 +88,47 @@ fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) {
}
#[test]
+fn unsized_from_keeps_type_info() {
+ check_types(
+ r#"
+//- minicore: coerce_unsized, from
+use core::{marker::Unsize, ops::CoerceUnsized};
+
+struct MyBox<T: ?Sized> {
+ ptr: *const T,
+}
+
+impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<MyBox<U>> for MyBox<T> {}
+
+struct MyRc<T: ?Sized> {
+ ptr: *const T,
+}
+
+impl<T: ?Sized> core::convert::From<MyBox<T>> for MyRc<T> {
+ fn from(_: MyBox<T>) -> MyRc<T> {
+ loop {}
+ }
+}
+
+fn make_box() -> MyBox<[i32; 2]> {
+ loop {}
+}
+
+fn take<T: ?Sized>(value: MyRc<T>) -> MyRc<T> {
+ value
+}
+
+fn test() {
+ let boxed: MyBox<[i32]> = make_box();
+ let rc = MyRc::from(boxed);
+ //^^ MyRc<[i32]>
+ let _: MyRc<[i32]> = take(rc);
+}
+"#,
+ );
+}
+
+#[test]
fn if_coerce() {
check_no_mismatches(
r#"