Skip to content

Commit d3a75c9

Browse files
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.
1 parent b800c8a commit d3a75c9

File tree

1 file changed

+41
-0
lines changed
  • src/tools/rust-analyzer/crates/hir-ty/src/tests

1 file changed

+41
-0
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,47 @@ fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) {
8787
);
8888
}
8989

90+
#[test]
91+
fn unsized_from_keeps_type_info() {
92+
check_types(
93+
r#"
94+
//- minicore: coerce_unsized, from
95+
use core::{marker::Unsize, ops::CoerceUnsized};
96+
97+
struct MyBox<T: ?Sized> {
98+
ptr: *const T,
99+
}
100+
101+
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<MyBox<U>> for MyBox<T> {}
102+
103+
struct MyRc<T: ?Sized> {
104+
ptr: *const T,
105+
}
106+
107+
impl<T: ?Sized> core::convert::From<MyBox<T>> for MyRc<T> {
108+
fn from(_: MyBox<T>) -> MyRc<T> {
109+
loop {}
110+
}
111+
}
112+
113+
fn make_box() -> MyBox<[i32; 2]> {
114+
loop {}
115+
}
116+
117+
fn take<T: ?Sized>(value: MyRc<T>) -> MyRc<T> {
118+
value
119+
}
120+
121+
fn test() {
122+
let boxed: MyBox<[i32]> = make_box();
123+
let rc = MyRc::from(boxed);
124+
//^^ MyRc<[i32]>
125+
let _: MyRc<[i32]> = take(rc);
126+
}
127+
"#,
128+
);
129+
}
130+
90131
#[test]
91132
fn if_coerce() {
92133
check_no_mismatches(

0 commit comments

Comments
 (0)