From 9709dff7e3b9aecd392465529790edd906d95037 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 7 May 2016 20:00:42 +0300 Subject: [PATCH] trans: monomorphize the cast destination type before using it. --- src/librustc_trans/mir/rvalue.rs | 2 ++ src/test/run-pass/mir_coercions.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 1236100a4d51..45b6bcd920fd 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -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. diff --git a/src/test/run-pass/mir_coercions.rs b/src/test/run-pass/mir_coercions.rs index c1897f79f22c..09dd52e30bef 100644 --- a/src/test/run-pass/mir_coercions.rs +++ b/src/test/run-pass/mir_coercions.rs @@ -55,6 +55,13 @@ fn coerce_fat_ptr_wrapper(p: PtrWrapper 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> +{ + 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 u32> = + coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local)); + assert_eq!((z.3)(6), 36); }