Skip to content

Commit 9709dff

Browse files
committed
trans: monomorphize the cast destination type before using it.
1 parent 50909f2 commit 9709dff

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/librustc_trans/mir/rvalue.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
5555
}
5656

5757
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
58+
let cast_ty = bcx.monomorphize(&cast_ty);
59+
5860
if common::type_is_fat_ptr(bcx.tcx(), cast_ty) {
5961
// into-coerce of a thin pointer to a fat pointer - just
6062
// use the operand path.

src/test/run-pass/mir_coercions.rs

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ fn coerce_fat_ptr_wrapper(p: PtrWrapper<Fn(u32) -> u32+Send>)
5555
p
5656
}
5757

58+
#[rustc_mir]
59+
fn coerce_ptr_wrapper_poly<'a, T, Trait: ?Sized>(p: PtrWrapper<'a, T>)
60+
-> PtrWrapper<'a, Trait>
61+
where PtrWrapper<'a, T>: CoerceUnsized<PtrWrapper<'a, Trait>>
62+
{
63+
p
64+
}
5865

5966
fn main() {
6067
let a = [0,1,2];
@@ -73,4 +80,8 @@ fn main() {
7380

7481
let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local));
7582
assert_eq!((z.3)(6), 36);
83+
84+
let z: PtrWrapper<Fn(u32) -> u32> =
85+
coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local));
86+
assert_eq!((z.3)(6), 36);
7687
}

0 commit comments

Comments
 (0)