Skip to content

Commit 2b0a77b

Browse files
authored
Merge pull request #21078 from asukaminato0721/20040
fix add test for Rc type inference failed #20040
2 parents bf077f8 + d3a75c9 commit 2b0a77b

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)