trans: monomorphize the cast destination type before using it.

This commit is contained in:
Eduard Burtescu 2016-05-07 20:00:42 +03:00
parent 50909f2d50
commit 9709dff7e3
2 changed files with 13 additions and 0 deletions

View File

@ -55,6 +55,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
}
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
let cast_ty = bcx.monomorphize(&cast_ty);
if common::type_is_fat_ptr(bcx.tcx(), cast_ty) {
// into-coerce of a thin pointer to a fat pointer - just
// use the operand path.

View File

@ -55,6 +55,13 @@ fn coerce_fat_ptr_wrapper(p: PtrWrapper<Fn(u32) -> u32+Send>)
p
}
#[rustc_mir]
fn coerce_ptr_wrapper_poly<'a, T, Trait: ?Sized>(p: PtrWrapper<'a, T>)
-> PtrWrapper<'a, Trait>
where PtrWrapper<'a, T>: CoerceUnsized<PtrWrapper<'a, Trait>>
{
p
}
fn main() {
let a = [0,1,2];
@ -73,4 +80,8 @@ fn main() {
let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local));
assert_eq!((z.3)(6), 36);
let z: PtrWrapper<Fn(u32) -> u32> =
coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local));
assert_eq!((z.3)(6), 36);
}